错误:setBackgroundColorTransparent()不是Google Apps脚本中的函数

问题描述 投票:1回答:1

我正在使用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)
google-apps-script google-sheets
1个回答
2
投票

我相信您的目标如下。

  • 为了将背景色设置为默认颜色,您尝试使用setBackgroundColorTransparent()
  • 您要设置单元格的背景色。

为此,这个答案如何?

修改点:

  • [遗憾的是,setBackgroundColorTransparent()的方法未包含在电子表格服务中。我认为您的问题的原因是这样的。我认为在您的情况下,可以使用Slides Service中的TextStyle类的setBackgroundColorTransparent()方法。 Ref
  • setBackgroundColor的方法未包含在“类别范围”中。在这种情况下,请使用setBackground

因此,当您要将背景色设置为默认值时,如何进行以下修改?

发件人:

currentRow.setBackgroundColor('#F87CF8');

收件人:

currentRow.setBackground('#F87CF8');

发件人:

currentRow.setBackgroundColorTransparent();

收件人:

currentRow.setBackground(null);

注意:

  • setBackgroundColor的方法不包括在“类别范围”中。但是从OP的答复中,发现可以使用此方法。

参考:

© www.soinside.com 2019 - 2024. All rights reserved.