【发布时间】:2018-02-25 14:36:02
【问题描述】:
我在原始表上使用 .getValues() 创建了一个多维数组 sheetValues[][]。我想将 sheetValues 数组中的值复制到目标工作表中。如何将 sheetValues 数组每一行的内容推送到目标工作表中?
什么函数允许我将数组的每一行一次推入(在检查 IF 条件后)到目标工作表的相应范围?
这里是sn-p的代码:
var ss = SpreadsheetApp.getActiveSpreadsheet();
var sheet = ss.getSheetByName("Source Sheet"); //Source sheet that has all data
var lastRow = sheet.getLastRow(); //last row number of Source sheet
var sheetValues = sheet.getRange(1, 1, lastRow, 18).getDisplayValues; //Copy Display values to an array; getDisplayValues() is used instead of getValues() to ignore formulas in the source cells such as "IMPORTRANGE"
var targetSheet = SpreadsheetApp.getActiveSpreadsheet().getSheetbyName('Target Sheet'); //destination sheet
var currentRow = targetSheet.getLastRow(); //current last row of the destination sheet (start copying after this row)
var target = targetSheet.getRange(currentRow+1, 1); //target range where the copying of data should begin in destination sheet
loop through each row of the array (sheetValues) to check if the status (column I) is 'On Target'; if yes, copy that entire row to the target range defined above
for (var i = 0; i <= lastRow; i++) {
if (sheetValues[i][9] == 'On Target') {
How do I copy/push the entire row at once (column 1 - 18) directly into the target range (currentRow, columns 1-18)? What function do I use?
}
currentRow++;
}
【问题讨论】: