我对java的了解很少。我已经创建了代码表,在这里咨询了5,6个代码和开发人员谷歌小组,但可以找出有条件的东西。
基本上我想将包含H列中“AAF”或“SEQ”或“K7”一词的整行复制到最后一行的另一张纸上。最终我想要删除复制的行。 我没有尝试实现lastrow也没有尝试删除行,但是现在我只是为了让副本与过滤条件一起工作。 如果我拿出“for”循环复制工作。
function copyrange() {
var sheet = SpreadsheetApp.getActiveSheet();
var destsheet = SpreadsheetApp.getActiveSpreadsheet().getSheetByName("Feuille2"); //destination sheet >where to copy the source
var rangeToCopy = sheet.getRange(1, 1, sheet.getMaxRows(), 11); //source to copy
var data = sheet.getDataRange().getValues(); //variable for the filter
for (n=0; n<data.length; ++n) {
if (data[n] == "AAF" || "SEQ" || "K7")
rangeToCopy.copyTo(destsheet.getRange(1, 1));
}
}
答案 0 :(得分:0)
终于找到了适合我的代码。
function Validation() {
var sheet1 = SpreadsheetApp.getActiveSpreadsheet().getSheetByName('Needed');
var sheet2 = SpreadsheetApp.getActiveSpreadsheet().getSheetByName('Acquired');
var data = sheet1.getRange(1,1, sheet1.getLastRow(), sheet1.getLastColumn()).getValues();
var dest = [];
for (var i = 0; i < data.length; i++ ) {
Logger.log(data[i][7]);// just to check if the condition is true sometimes ;-)
if (data[i][7] == "AAF" || data[i][7] == "SEQ" || data[i][7] == "K7"){
dest.push(data[i]);
}
} // here is the end of the for loop
Logger.log(dest) ; // log the dest array instead
if (dest.length > 0 ) { // if something has been written in your array then batch write it to the dest. sheet
sheet2.getRange(sheet2.getLastRow()+1,1,dest.length,dest[0].length).setValues(dest);
}
}