我正在使用Google Apps脚本更改Google表格中某些单元格行的背景颜色。由于某种原因,当我将它们作为一系列单元格的函数运行时(不是我尝试过的其他方法),setBackgroundColor('white')可以工作,而setBackgroundColorTransparent()会调用“ TypeError:not a function”消息。我是否缺少setBackgroundColorTransparent()的用法或语法?
我的代码:
function colorSundays() {
var maxColumns = sheet.getMaxColumns();
for (i = 1; i <= 31; i++) {
var currentCell = sheet.getRange(i, 1);
var value = currentCell.getValues();
if (value == 'Sunday') {
var currentRow = sheet.getRange(i, 1, 1, maxColumns);
currentRow.setBackgroundColor('#F87CF8');
} else {
var currentRow = sheet.getRange(i, 1, 1, maxColumns);
// currentRow.setBackgroundColor('white');
currentRow.setBackgroundColorTransparent(); // Preferred, but now working right now.
}
}
}
错误消息:
[20-06-08 19:09:04:246 CDT] TypeError: currentRow.setBackgroundColorTransparent is not a function
at colorSundays(Code:52:18)
at setThisMonth(Code:61:3)
我相信您的目标如下。
setBackgroundColorTransparent()
。为此,这个答案如何?
setBackgroundColorTransparent()
的方法未包含在电子表格服务中。我认为您的问题的原因是这样的。我认为在您的情况下,可以使用Slides Service中的TextStyle类的setBackgroundColorTransparent()
方法。 RefsetBackgroundColor
的方法未包含在“类别范围”中。在这种情况下,请使用setBackground
。因此,当您要将背景色设置为默认值时,如何进行以下修改?
currentRow.setBackgroundColor('#F87CF8');
currentRow.setBackground('#F87CF8');
和
currentRow.setBackgroundColorTransparent();
currentRow.setBackground(null);
setBackgroundColor
的方法不包括在“类别范围”中。但是从OP的答复中,发现可以使用此方法。