Last updated 2 years ago
Was this helpful?
sheet.appendConditionalFormatRule()
// cells in A1:B3 will turn red if 1 <= value <= 10 var sheet = SpreadsheetApp.getActiveSheet(); var range = sheet.getRange("A1:B3"); var rule = SpreadsheetApp .newConditionalFormatRule() // ⭐️ ConditionalFormatRuleBuilder .whenNumberBetween(1, 10) // - 🔸 condition .setBackground("#FF0000") // - 🔸 formats .setRanges([range]) // - 🔸 ranges .build(); // ⭐️ ConditionalFormatRule // append new rule to existing rules (instead of overwriting it) var rules = sheet.getConditionalFormatRules(); rules.push(rule); sheet.setConditionalFormatRules(rules);
⭐️ 注意:
當使用 , ... 等這些與數字相關的條件時,儲存格的值必須是「」才行,否則前面設的那些條件都沒有用❗️
⭐️
SpreadsheetApp ⟩
- returns
range.setNumberFormat() - 使用條件時,要注意儲存格「」。