我正在尝试构建一个具有for循环的函数,并在找到某些条件时更改行的颜色。但是当我尝试下面的代码时,我收到一个错误:TypeError: Cannot find function getRowIndex in object Sheet.
。所以,在这种情况下,假设我在i
变量中有行位置,我怎样才能使用i
值,以一种我可以改变背景的方式选择工作表中的相应行整行?
var ss = SpreadsheetApp.getActiveSpreadsheet();
var sourceSpreadsheetID = ss.getId();
var oldSpreadsheet = SpreadsheetApp.openById(sourceSpreadsheetID);
var oldWorksheet = oldSpreadsheet.getSheetByName("students");
var newData = newWorksheet.getDataRange().getValues();
// Iterates through the new sheet rows
for(i=1; i<newData.length; i++){
var currentRow = oldWorksheet.getRowIndex(i);
currentRow.setBackgroundRGB(255, 222, 173).setNote("any note");
}
答案 0 :(得分:0)
我建议您使用“Sheet”类型的getRange()函数来完成此任务。
var currentRow = oldWorksheet. getRange(i (specify the row here), column(Specify the number of columns here))
currentRow.setBackgroundRGB(255, 222, 173).setNote("any note");