Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/google-apps-script/6.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Google apps script 使用Google Apps脚本将数据从阵列复制/推送到工作表范围内,每次一行_Google Apps Script - Fatal编程技术网

Google apps script 使用Google Apps脚本将数据从阵列复制/推送到工作表范围内,每次一行

Google apps script 使用Google Apps脚本将数据从阵列复制/推送到工作表范围内,每次一行,google-apps-script,Google Apps Script,我使用原始工作表上的.getValues()创建了多维数组sheetValues[]]。我想将sheetValues数组中的值复制到目标工作表中。如何将sheetValues数组每行的内容推送到目标工作表中 什么函数允许我将数组的每一行(在检查IF条件后)推入目标工作表的相应范围 以下是代码片段: var ss = SpreadsheetApp.getActiveSpreadsheet(); var sheet = ss.getSheetByName("Source Sheet"); //Sou

我使用原始工作表上的.getValues()创建了多维数组sheetValues[]]。我想将sheetValues数组中的值复制到目标工作表中。如何将sheetValues数组每行的内容推送到目标工作表中

什么函数允许我将数组的每一行(在检查IF条件后)推入目标工作表的相应范围

以下是代码片段:

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++;
}
var ss=SpreadsheetApp.getActiveSpreadsheet();
var sheet=ss.getSheetByName(“源表”)//包含所有数据的源工作表
var lastRow=sheet.getLastRow()//源工作表的最后行号
var sheetValues=sheet.getRange(1,1,lastRow,18).getDisplayValues//将显示值复制到数组;使用getDisplayValues()代替getValues()忽略源单元格中的公式,如“IMPORTRANGE”
var targetSheet=SpreadsheetApp.getActiveSpreadsheet().getSheetbyName('targetSheet')//目的地表
var currentRow=targetSheet.getLastRow()//目标工作表的当前最后一行(在此行之后开始复制)
var target=targetSheet.getRange(currentRow+1,1)//在目标工作表中开始复制数据的目标范围
循环遍历数组的每一行(sheetValues),以检查状态(列I)是否为“目标”;如果是,将整行复制到上面定义的目标范围

for(var i=0;i从不“一次推送数组中的每一行”。这是一个笨拙的代码,启动速度非常慢。设置值与获取值非常相似。您可以声明一个范围变量,该变量具有适合值[][]数组维度的适当坐标,并将整个值数组传递给“setValues()'范围对象的方法

getRange()的方法签名之一如下:

sheet.getRange(row, column, numberOfRows, numberOfColumns);
更多信息

前两个参数用于范围中最左上方的单元格,而其他参数用于定义范围应跨越的行数和列数

假设您希望开始从目标工作表中的第一个单元格插入值,下面是您需要的一行代码

sheet.getRange(1, 1, sheetValues.length, sheetValues[0].length);
行数是数组的长度,列数是数组第一个元素(行)的长度

更新

我错过了隐藏在代码中的注释。您可以在将值写入目标工作表之前对其进行筛选

sheetValues = sheetValues.map(function(row){

if (row[9] == 'Target') { return row;  }

});