Class GradientCondition

  • GradientCondition is used to access gradient color conditions in ConditionalFormatRuleApis.

  • A gradient condition is defined by three points (min, mid, max), each with a color, value, and InterpolationType.

  • Cell colors are interpolated based on their content's proximity to the min, mid, and max points of the gradient condition.

  • Methods are available to get the color object, interpolation type, and value for the min, mid, and max points.

  • Some methods for getting color as a string are deprecated and replaced by methods returning Color objects.

GradientCondition

Access gradient (color) conditions inConditionalFormatRuleApis.Each conditional format rule may contain a single gradient condition. A gradient condition isdefined by three points along a number scale (min, mid, and max), each of which has a color, avalue, and aInterpolationType. The content of a cell iscompared to the values in the number scale and the color applied to the cell is interpolatedbased on the cell content's proximity to the gradient condition min, mid, and max points.

// Logs all the information inside gradient conditional format rules on a sheet.// The below snippet assumes all colors have ColorType.RGB.constsheet=SpreadsheetApp.getActiveSheet();construles=sheet.getConditionalFormatRules();for(leti=0;i <rules.length;i++){constgradient=rules[i].getGradientCondition();constminColor=gradient.getMinColorObject().asRgbColor().asHexString();constminType=gradient.getMinType();constminValue=gradient.getMinValue();constmidColor=gradient.getMidColorObject().asRgbColor().asHexString();constmidType=gradient.getMidType();constmidValue=gradient.getMidValue();constmaxColor=gradient.getMaxColorObject().asRgbColor().asHexString();constmaxType=gradient.getMaxType();constmaxValue=gradient.getMaxValue();Logger.log(`The conditional format gradient information for rule${i}:    MinColor${minColor}, MinType${minType}, MinValue${minValue},    MidColor${midColor}, MidType${midType}, MidValue${midValue},    MaxColor${maxColor}, MaxType${maxType}, MaxValue${maxValue}`);}

Methods

MethodReturn typeBrief description
getMaxColorObject()Color|nullGets the color set for the maximum value of this gradient condition.
getMaxType()InterpolationType|nullGets the interpolation type for the maximum value of this gradient condition.
getMaxValue()StringGets the max value of this gradient condition.
getMidColorObject()Color|nullGets the color set for the midpoint value of this gradient condition.
getMidType()InterpolationType|nullGets the interpolation type for the midpoint value of this gradient condition.
getMidValue()StringGets the midpoint value of this gradient condition.
getMinColorObject()Color|nullGets the color set for the minimum value of this gradient condition.
getMinType()InterpolationType|nullGets the interpolation type for the minimum value of this gradient condition.
getMinValue()StringGets the minimum value of this gradient condition.

Deprecated methods

MethodReturn typeBrief description
getMaxColor()StringGets the color set for the maximum value of this gradient condition.
getMidColor()StringGets the color set for the midpoint value of this gradient condition.
getMinColor()StringGets the color set for the minimum value of this gradient condition.

Detailed documentation

getMaxColorObject()

Gets the color set for the maximum value of this gradient condition. Returnsnull ifthe color hasn't been set.

Return

Color|null — The color set for the maximum value of this gradient condition ornull.


getMaxType()

Gets the interpolation type for the maximum value of this gradient condition. Returnsnull if the gradient max type hasn't been set.

Return

InterpolationType|null — The interpolation type for the maximum value of this gradient condition ornull.


getMaxValue()

Gets the max value of this gradient condition. Returns an empty string if theInterpolationType isMAX or if the max value hasn't beenset.

Return

String — The maximum value if specified or an empty string.


getMidColorObject()

Gets the color set for the midpoint value of this gradient condition. Returnsnull ifthe color hasn't been set.

Return

Color|null — The color set for the midpoint value of this gradient condition ornull.


getMidType()

Gets the interpolation type for the midpoint value of this gradient condition. Returnsnull if the gradient mid type hasn't been set.

Return

InterpolationType|null — The interpolation type for the midpoint value of this gradient condition ornull.


getMidValue()

Gets the midpoint value of this gradient condition. Returns an empty string if the gradient midvalue hasn't been set.

Return

String — The midpoint value or an empty string.


getMinColorObject()

Gets the color set for the minimum value of this gradient condition. Returnsnull ifthe color hasn't been set.

Return

Color|null — The color set for the minimum value of this gradient condition ornull.


getMinType()

Gets the interpolation type for the minimum value of this gradient condition. Returnsnull if the gradient min type hasn't been set.

Return

InterpolationType|null — The interpolation type for the minimum value of this gradient condition ornull.


getMinValue()

Gets the minimum value of this gradient condition. Returns an empty string if theInterpolationType isMIN or if the min value hasn't beenset.

Return

String — The minimum value if specified or an empty string.

Deprecated methods

getMaxColor()

Deprecated. Replaced bygetMaxColorObject()

Gets the color set for the maximum value of this gradient condition. Returns an empty string ifthe color hasn't been set.

Return

String — The color set for the maximum value of this gradient condition or an empty string.


getMidColor()

Deprecated. Replaced bygetMidColorObject()

Gets the color set for the midpoint value of this gradient condition. Returns an empty stringif the color hasn't been set.

Return

String — The color set for the midpoint value of this gradient condition or an empty string.


getMinColor()

Deprecated. Replaced bygetMinColorObject()

Gets the color set for the minimum value of this gradient condition. Returns an empty string ifthe color hasn't been set.

Return

String — The color set for the minimum value of this gradient condition or an empty string.

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.