google-apps-script - 错误:setBackgroundColorTransparent() 不是 Google Apps 脚本中的函数
问题描述
我正在使用 Google Apps 脚本更改 Google 表格中某些单元格行的背景颜色。出于某种原因,当我将它们作为一系列单元格的函数运行时(不是我尝试过的其他方法),setBackgroundColor('white') 有效,而 setBackgroundColorTransparent() 调用“TypeError:不是函数”消息。我是否遗漏了 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()
电子表格服务中不包含 的方法。我认为你的问题的原因是这个。我认为在您的情况下,setBackgroundColorTransparent()
可能会使用 Slides Service 中 Class TextStyle 的方法。参考 - 的方法
setBackgroundColor
不包含在类范围中。在这种情况下,请使用setBackground
.
那么当你想将背景颜色设置为默认时,下面的修改呢?
从:
currentRow.setBackgroundColor('#F87CF8');
至:
currentRow.setBackground('#F87CF8');
和
从:
currentRow.setBackgroundColorTransparent();
至:
currentRow.setBackground(null);
笔记:
- 的方法
setBackgroundColor
不包含在类范围中。但是从OP的回复中发现可以使用这种方法。
参考:
推荐阅读
- php - 在 phpcs 中包含迁移文件
- spring - 将整数转换为 JSON
- r - 使用 ggplot2 在 R 中标记线性函数
- static - 如何将虚拟网络中的动态专用 IP 地址更改为容器组(Azure 容器实例)的静态(不变)IP 地址
- javascript - 如何获取在 NodeJS 的另一个文件中声明的变量的动态值
- swift - 如何获得更快的数据矩阵代码读取?
- bash - 为什么我的变量没有改变?Bash 脚本
- ajax - ajax 请求 asp.net mvc 将 id 值从 ajax 请求传递到控制器
- sockets - 我尝试使用 s_client (openssl) 和 javax.net.ssl 包连接到加密套接字
- sql - 如何在postgresql中计算中位数