Class ConditionalFormatRule

  • UseSpreadsheetApp.newConditionalFormatRule() andConditionalFormatRuleBuilder to create new conditional formatting rules.

  • You can set conditional format rules for a sheet usingSheet.setConditionalFormatRules().

  • Methods available forConditionalFormatRule includecopy(),getBooleanCondition(),getGradientCondition(), andgetRanges().

  • copy() returns a builder preset with the current rule's settings.

  • getBooleanCondition() andgetGradientCondition() retrieve condition details if applicable, otherwise returnnull.

  • getRanges() returns the ranges where the conditional format rule is applied.

ConditionalFormatRule

Access conditional formatting rules. To create a new rule, useSpreadsheetApp.newConditionalFormatRule() andConditionalFormatRuleBuilder.You can useSheet.setConditionalFormatRules(rules) to set therules for a given sheet.

Methods

MethodReturn typeBrief description
copy()ConditionalFormatRuleBuilderReturns a rule builder preset with this rule's settings.
getBooleanCondition()BooleanCondition|nullRetrieves the rule'sBooleanCondition information if this rule usesboolean condition criteria.
getGradientCondition()GradientCondition|nullRetrieves the rule'sGradientCondition information, if this ruleuses 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'sBooleanCondition information if this rule usesboolean condition criteria. Otherwise returnsnull.

// Log the boolean criteria type of the first conditional format rules of a// sheet.construle=SpreadsheetApp.getActiveSheet().getConditionalFormatRules()[0];constbooleanCondition=rule.getBooleanCondition();if(booleanCondition!=null){Logger.log(booleanCondition.getCriteriaType());}

Return

BooleanCondition|null — The boolean condition object, ornull if the rule does not use a boolean condition.


getGradientCondition()

Retrieves the rule'sGradientCondition information, if this ruleuses gradient condition criteria. Otherwise returnsnull.

// Log the gradient minimum color of the first conditional format rule of a// sheet.construle=SpreadsheetApp.getActiveSheet().getConditionalFormatRules()[0];constgradientCondition=rule.getGradientCondition();if(gradientCondition!=null){// Assume the color has ColorType.RGB.Logger.log(gradientCondition.getMinColorObject().asRgbColor().asHexString());}

Return

GradientCondition|null — The gradient condition object, ornull 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.construle=SpreadsheetApp.getActiveSheet().getConditionalFormatRules()[0];constranges=rule.getRanges();for(leti=0;i <ranges.length;i++){Logger.log(ranges[i].getA1Notation());}

Return

Range[] — The ranges to which this conditional format rule is applied.

Except as otherwise noted, the content of this page is licensed under theCreative Commons Attribution 4.0 License, and code samples are licensed under theApache 2.0 License. For details, see theGoogle Developers Site Policies. Java is a registered trademark of Oracle and/or its affiliates.

Last updated 2025-12-11 UTC.