我在旧帖子中看到了你的答案,我想要求澄清。这是我所指的主题:Copy every row of Data from one sheet that has a given value in column K to another sheet
我的问题是,我正在使用你的骨架脚本版本,但我遇到了一些麻烦。它不是复制整行的脚本,而是复制条件行中的第一列,并将所有数组的结果粘贴在一行中。
这是我的脚本:
function formSubmitCriticalAltThree(){
var ss = SpreadsheetApp.getActiveSpreadsheet();
var sheet = ss.getSheetByName("Form Responses");
var lastRow = ss.getLastRow();
var target = ss.getSheetByName("Chad");
var data = sheet.getDataRange().getValues();
var line = new Array();
var targetArray= new Array();
for (n=0;n<data.length;++n){ // iterate rows
if (data[n][10] == "cbellani"){ // if condition is true copy the whole row to target
line.push(data[n]);// copy the whole row
}//if
}//for
if(line.length>0){// if there is something to copy
targetArray.push(line)}// add row to destination
target.getRange(3,1,targetArray.length,targetArray[0].length).setValues(targetArray);
}
对此的任何帮助将不胜感激。
答案 0 :(得分:0)
我没有对此进行测试,但我认为它应该是这样的:
function formSubmitCriticalAltThree(){
var ss = SpreadsheetApp.getActiveSpreadsheet();
var sheet = ss.getSheetByName("Form Responses");
var lastRow = ss.getLastRow();
var target = ss.getSheetByName("Chad");
var data = sheet.getDataRange().getValues();
var targetArray = new Array();
for (var n = 0; n < data.length; ++n){ // iterate rows
if (data[n][10] == "cbellani") { // if condition is true copy the whole row to target
targetArray.push(data[n])}// add row to destination
}//if
}//for
target.getRange(3,1,targetArray.length,targetArray[0].length).setValues(targetArray);
}