我正在尝试为几个单元格设置背景颜色,然后在延迟之后将背景颜色设置回原始值。我希望颜色变成"黄色"在Utilities.sleep(10000)调用之前,然后在将它们重置为之前的背景颜色值后再次更改。
相反,颜色更改仅在脚本结束后发生。在下面的代码中,我从未看到对"黄色"的更改。如果我注释掉最后一次setbackgrounds调用。 "黄色"脚本完成后会出现背景。
function updateSprintValues2(sprintRow,totalRow) {
// read the values in the totalRow for Completed (L-11), Planned Scope (M-12)
// update the sprints Completed value (D-3) and Planned Scope (E-4)
var colcomp = 4;
var colplanned = 5;
var totcomp = 11;
var totplanned = 12;
var ss = SpreadsheetApp.getActiveSpreadsheet();
var sheet = ss.getActiveSheet();
var rows = sheet.getDataRange();
var values = rows.getValues();
var cells = sheet.getRange(Number(sprintRow),colcomp,1,2);
var pprevbackground = cells.getBackgrounds();
cells.setBackgrounds([["yellow","yellow"]]);
cells.setValues([[values[totalRow][totcomp],values[totalRow][totplanned]]]);
var thiscell = sheet.getActiveCell().activateAsCurrentCell();
Utilities.sleep(10000);
cells.setBackgrounds(pprevbackground);
cells.setValues([[values[totalRow][totcomp],values[totalRow][totplanned]]]);
}