【发布时间】:2021-02-22 11:39:26
【问题描述】:
根据文件:https://developers.google.com/apps-script/reference/spreadsheet/conditional-format-rule-builder
var sheet = SpreadsheetApp.getActiveSheet();
但我只希望它出现在名为 Resultat 的特殊工作表中。
var sheet = SpreadsheetApp.getActiveSpreadsheet().getSheetByName("resultat");
但是有了这个 sheetByName,我得到了:
TypeError: ThisSheet.newConditionalFormatRule is not a function
调用代码:
var ThisSheet = SpreadsheetApp.getActiveSpreadsheet().getSheetByName("resultat");
var range = ThisSheet.getRange("C:D") // only want it to select C element.
ThisSheet.clearConditionalFormatRules();
var rule1 = ThisSheet.newConditionalFormatRule()
.whenTextContains("NO")
.setBackground("#b3cfb0")
.setRanges([range])
.build();
var rules = ThisSheet.getConditionalFormatRules();
rules.push(rule1);
ThisSheet.setConditionalFormatRules(rules);
【问题讨论】:
-
是错字吗?你想要
sheet而不是ThisSheet吗?ThisSheet定义在哪里? -
你的权利@marios
-
@maria jsfiddle.net/q8fcsL05(无关)
标签: google-apps-script google-sheets conditional-formatting