[英]How do I run Loop correctly in Google Apps Script
I`m trying to copy and paste an array from a sheet called "home" to another called "db".我正在尝试将数组从名为“home”的工作表复制并粘贴到另一个名为“db”的工作表中。 For some reason, the last row it is not set correctly in db sheet.
由于某种原因,最后一行在 db 表中未正确设置。 See the code below:
请看下面的代码:
function myFunction() {
var home = SpreadsheetApp.getActive().getSheets()[0];
var db = SpreadsheetApp.getActive().getSheetByName("db");
var lastrowhome = home.getRange('C10:C100').getLastRow();
var lastrowdb = db.getLastRow();
for (var i = 10; i <= lastrowhome; i++){
var copy = home.getRange(i, 3);
var paste = db.getRange(lastrowdb+1,3);
paste.setValues(copy.getValues());
}
}
Furthermore, the code demands too much time to finish此外,代码需要太多时间才能完成
thanks!谢谢!
function myFunction() {
const ss = SpreadsheetApp.getActive();
const home = ss.getSheetByName("home");
const db = ss.getSheetByName("db");
const sr = 10
const vs = home.getRange(sr, 1, sh.getLastRow() - sr + 1, sh.getLastColumn()).getValues();
db.getRange(sr,1,vs.length,vs[0].length).setValues(vs);
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.