-有人可以帮助我检查此代码,因为即使满足条件,它仍会设置所有数据的值。仅在满足条件时才更新数据。
var ss = SpreadsheetApp.openById('id');
var sheet = ss.getSheetByName("VL Request");
var range = sheet.getDataRange();
var values = range.getValues();
var rid = [1];
// writes the form data to the spreadsheet
for (var i = 1; i <= values.length; i++) {
var sel = sheet.getRange(i, 2).getValue();
if (sel = ReqNum) {
sheet.getRange(i, 14).setValue(pri);
sheet.getRange(i, 16).setValue(stat);
sheet.getRange(i, 18).setValue(rem);
}
}
答案 0 :(得分:1)
尝试一下:
function unknown() {
var ss=SpreadsheetApp.openById('id');
var sheet=ss.getSheetByName("VL Request");
var range=sheet.getRange(2,1,sheet.getLastRow()-1,18);
var values=range.getValues();
for(var i=0;i<values.length;i++) {
if(values[i][1]==ReqNum) {//First time through is row 2 column 2
sheet.getRange(i+2, 14).setValue(pri);//i+2 is the row, 14 is the column
sheet.getRange(i+2, 16).setValue(stat);//the first time through is row 2, column16
sheet.getRange(i+2, 18).setValue(rem);
}
}
}