条件格式谷歌应用程序脚本



我已经为谷歌应用程序脚本编写了一个条件格式规则,但我收到了一个错误"getConditionalFormatRules不是函数"有人能帮我看看我是否犯了错误吗?我希望任何低于50%的都是红色,任何在50%到70%之间的都是黄色,任何超过70%的都是绿色。应用程序脚本文档说getConditionalFormatRules是一个函数,所以不确定发生了什么

function percentAtMasteryConditionalFormat(){
var sheet = SpreadsheetApp.getActiveSpreadsheet();
var range = sheet.getActiveRange();
range.setFontSize(10);
range.setFontFamily("Didact Gothic");

var percentAtMasteryrule = SpreadsheetApp.newConditionalFormatRule()
.whenNumberLessThan(0.5)
.setBackground("#f4c7c3")
.setFontColor("#5F1625")
.whenNumberBetween(0.5,0.7)
.setBackground("#fce8b2")
.setFontColor("#e8ba39")
.whenNumberGreaterThan(0.7)
.setBackground("#a8e6ce")
.setFontColor("#264d59")
.setRanges([range])
.build();
var rules = sheet.getConditionalFormatRules();
rules.push(percentAtMasteryrule);
sheet.setConditionalFormatRules(rules);

var rules = sheet.getConditionalFormatRules();

表格需要是班级表格的成员,而不是班级电子表格

getConditionalFormatRules()应应用于类Sheet。类别Spreadsheet不同。

代码:

var sheet = SpreadsheetApp.getActiveSheet();
var range = sheet.getActiveRange();
...
var rules = sheet.getConditionalFormatRules();
rules.push(percentAtMasteryrule);
sheet.setConditionalFormatRules(rules);

文档:

类ConditionalFormatBuilder

相关内容

最新更新