一种选择是创建自己的函数(一种包装器),例如(您需要应用必要的验证):
/* CODE FOR DEMONSTRATION PURPOSES */
function setColorToRange() {
var ss = SpreadsheetApp.getActiveSpreadsheet();
var sheet = ss.getActiveSheet();
var colorsRGB = [
[
[255, 0, 0],
[0, 255, 0],
[0, 0, 255],
[0, 0, 0]
],
[
[0, 0, 0],
[0, 0, 255],
[0, 255, 0],
[255, 0, 0]
],
[
[0, 255, 0],
[0, 255, 0],
[0, 255, 0],
[0, 255, 0]
]
];
var cell = sheet.getRange("B5:E7");
setBackgroundsRGB(cell, colorsRGB);
}
function setBackgroundsRGB(range, colors) {
var row = range.getRow(), lastRow = range.getLastRow();
var initColumn = range.getColumn(), lastColumn = range.getLastColumn(), column;
var ss = range.getSheet(), colorRow, colorColumn, subRange;
for (colorRow = 0; row <= lastRow; ++row, ++colorRow) {
for (column = initColumn, colorColumn = 0; column <= lastColumn; ++column) {
subRange = ss.getRange(row, column);
subRange.setBackgroundRGB.apply(subRange, colors[colorRow][colorColumn++]);
}
}
}
/* CODE FOR DEMONSTRATION PURPOSES */