Access conditional formatting rules. To create a new rule, use SpreadsheetApp.newConditionalFormatRule()
and ConditionalFormatRuleBuilder
.
You can use Sheet.setConditionalFormatRules(rules)
to set the
rules for a given sheet.
Methods
Method | Return type | Brief description |
---|---|---|
copy() | ConditionalFormatRuleBuilder | Returns a rule builder preset with this rule's settings. |
getBooleanCondition() | BooleanCondition | Retrieves the rule's BooleanCondition information if this rule uses
boolean condition criteria. |
getGradientCondition() | GradientCondition | Retrieves the rule's GradientCondition information, if this rule
uses gradient condition criteria. |
getRanges() | Range[] | Retrieves the ranges to which this conditional format rule is applied. |
Detailed documentation
copy()
Returns a rule builder preset with this rule's settings.
Return
ConditionalFormatRuleBuilder
— a builder based on this rule's settings
getBooleanCondition()
Retrieves the rule's BooleanCondition
information if this rule uses
boolean condition criteria. Otherwise returns null
.
// Log the boolean criteria type of the first conditional format rules of a sheet. var rule = SpreadsheetApp.getActiveSheet().getConditionalFormatRules()[0]; var booleanCondition = rule.getBooleanCondition(); if (booleanCondition != null) { Logger.log(booleanCondition.getCriteriaType()); }
Return
BooleanCondition
— the boolean condition object, or null
if the rule does not use a boolean
condition.
getGradientCondition()
Retrieves the rule's GradientCondition
information, if this rule
uses gradient condition criteria. Otherwise returns null
.
// Log the gradient minimum color of the first conditional format rule of a sheet. var rule = SpreadsheetApp.getActiveSheet().getConditionalFormatRules()[0]; var gradientCondition = rule.getGradientCondition(); if (gradientCondition != null) { // Assume the color has ColorType.RGB. Logger.log(gradientCondition.getMinColorObject().asRgbColor().asHexString()); }
Return
GradientCondition
— The gradient condition object, or null
if the rule does not use a gradient
condition.
getRanges()
Retrieves the ranges to which this conditional format rule is applied.
// Log each range of the first conditional format rule of a sheet. var rule = SpreadsheetApp.getActiveSheet().getConditionalFormatRules()[0]; var ranges = rule.getRanges(); for (var i = 0; i < ranges.length; i++) { Logger.log(ranges[i].getA1Notation()); }
Return
Range[]
— the ranges to which this conditional format rule is applied.