🍄ConditionalFormatRule
// 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);⭐️ 注意:
當使用 whenNumberBetween(start, end), whenNumberEqualTo(number) ... 等這些與數字相關的條件時,儲存格的值必須是「數字格式」才行,否則前面設的那些條件都沒有用❗️
- SpreadsheetApp ⟩ 
- range.setNumberFormat() - 使用條件時,要注意儲存格「值的格式」。 
Last updated
Was this helpful?