Class GradientCondition | Apps Script | Google for Developers (original) (raw)
Class GradientCondition
Stay organized with collections Save and categorize content based on your preferences.
GradientCondition
Access gradient (color) conditions in [ConditionalFormatRuleApis](/apps-script/reference/spreadsheet/conditional-format-rule)
. Each conditional format rule may contain a single gradient condition. A gradient condition is defined by three points along a number scale (min, mid, and max), each of which has a color, a value, and a [InterpolationType](/apps-script/reference/spreadsheet/interpolation-type)
. The content of a cell is compared to the values in the number scale and the color applied to the cell is interpolated based 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. const sheet = SpreadsheetApp.getActiveSheet(); const rules = sheet.getConditionalFormatRules(); for (let i = 0; i < rules.length; i++) { const gradient = rules[i].getGradientCondition();
const minColor = gradient.getMinColorObject().asRgbColor().asHexString(); const minType = gradient.getMinType(); const minValue = gradient.getMinValue(); const midColor = gradient.getMidColorObject().asRgbColor().asHexString(); const midType = gradient.getMidType(); const midValue = gradient.getMidValue(); const maxColor = gradient.getMaxColorObject().asRgbColor().asHexString(); const maxType = gradient.getMaxType(); const maxValue = gradient.getMaxValue();
Logger.log(The conditional format gradient information for rule ${i}: MinColor <span class="katex"><span class="katex-mathml"><math xmlns="http://www.w3.org/1998/Math/MathML"><semantics><mrow><mrow><mi>m</mi><mi>i</mi><mi>n</mi><mi>C</mi><mi>o</mi><mi>l</mi><mi>o</mi><mi>r</mi></mrow><mo separator="true">,</mo><mi>M</mi><mi>i</mi><mi>n</mi><mi>T</mi><mi>y</mi><mi>p</mi><mi>e</mi></mrow><annotation encoding="application/x-tex">{minColor}, MinType </annotation></semantics></math></span><span class="katex-html" aria-hidden="true"><span class="base"><span class="strut" style="height:0.8889em;vertical-align:-0.1944em;"></span><span class="mord"><span class="mord mathnormal">min</span><span class="mord mathnormal" style="margin-right:0.07153em;">C</span><span class="mord mathnormal">o</span><span class="mord mathnormal" style="margin-right:0.01968em;">l</span><span class="mord mathnormal" style="margin-right:0.02778em;">or</span></span><span class="mpunct">,</span><span class="mspace" style="margin-right:0.1667em;"></span><span class="mord mathnormal" style="margin-right:0.10903em;">M</span><span class="mord mathnormal">in</span><span class="mord mathnormal" style="margin-right:0.13889em;">T</span><span class="mord mathnormal" style="margin-right:0.03588em;">y</span><span class="mord mathnormal">p</span><span class="mord mathnormal">e</span></span></span></span>{minType}, MinValue ${minValue}, MidColor <span class="katex"><span class="katex-mathml"><math xmlns="http://www.w3.org/1998/Math/MathML"><semantics><mrow><mrow><mi>m</mi><mi>i</mi><mi>d</mi><mi>C</mi><mi>o</mi><mi>l</mi><mi>o</mi><mi>r</mi></mrow><mo separator="true">,</mo><mi>M</mi><mi>i</mi><mi>d</mi><mi>T</mi><mi>y</mi><mi>p</mi><mi>e</mi></mrow><annotation encoding="application/x-tex">{midColor}, MidType </annotation></semantics></math></span><span class="katex-html" aria-hidden="true"><span class="base"><span class="strut" style="height:0.8889em;vertical-align:-0.1944em;"></span><span class="mord"><span class="mord mathnormal">mi</span><span class="mord mathnormal">d</span><span class="mord mathnormal" style="margin-right:0.07153em;">C</span><span class="mord mathnormal">o</span><span class="mord mathnormal" style="margin-right:0.01968em;">l</span><span class="mord mathnormal" style="margin-right:0.02778em;">or</span></span><span class="mpunct">,</span><span class="mspace" style="margin-right:0.1667em;"></span><span class="mord mathnormal" style="margin-right:0.10903em;">M</span><span class="mord mathnormal">i</span><span class="mord mathnormal">d</span><span class="mord mathnormal" style="margin-right:0.13889em;">T</span><span class="mord mathnormal" style="margin-right:0.03588em;">y</span><span class="mord mathnormal">p</span><span class="mord mathnormal">e</span></span></span></span>{midType}, MidValue ${midValue}, MaxColor <span class="katex"><span class="katex-mathml"><math xmlns="http://www.w3.org/1998/Math/MathML"><semantics><mrow><mrow><mi>m</mi><mi>a</mi><mi>x</mi><mi>C</mi><mi>o</mi><mi>l</mi><mi>o</mi><mi>r</mi></mrow><mo separator="true">,</mo><mi>M</mi><mi>a</mi><mi>x</mi><mi>T</mi><mi>y</mi><mi>p</mi><mi>e</mi></mrow><annotation encoding="application/x-tex">{maxColor}, MaxType </annotation></semantics></math></span><span class="katex-html" aria-hidden="true"><span class="base"><span class="strut" style="height:0.8889em;vertical-align:-0.1944em;"></span><span class="mord"><span class="mord mathnormal">ma</span><span class="mord mathnormal">x</span><span class="mord mathnormal" style="margin-right:0.07153em;">C</span><span class="mord mathnormal">o</span><span class="mord mathnormal" style="margin-right:0.01968em;">l</span><span class="mord mathnormal" style="margin-right:0.02778em;">or</span></span><span class="mpunct">,</span><span class="mspace" style="margin-right:0.1667em;"></span><span class="mord mathnormal" style="margin-right:0.10903em;">M</span><span class="mord mathnormal">a</span><span class="mord mathnormal">x</span><span class="mord mathnormal" style="margin-right:0.13889em;">T</span><span class="mord mathnormal" style="margin-right:0.03588em;">y</span><span class="mord mathnormal">p</span><span class="mord mathnormal">e</span></span></span></span>{maxType}, MaxValue ${maxValue}
);
}
Methods
Method | Return type | Brief description |
---|---|---|
getMaxColorObject() | Color | Gets the color set for the maximum value of this gradient condition. |
getMaxType() | InterpolationType | Gets the interpolation type for the maximum value of this gradient condition. |
getMaxValue() | String | Gets the max value of this gradient condition. |
getMidColorObject() | Color | Gets the color set for the midpoint value of this gradient condition. |
getMidType() | InterpolationType | Gets the interpolation type for the mid-point value of this gradient condition. |
getMidValue() | String | Gets the mid-point value of this gradient condition. |
getMinColorObject() | Color | Gets the color set for the minimum value of this gradient condition. |
getMinType() | InterpolationType | Gets the interpolation type for the minimum value of this gradient condition. |
getMinValue() | String | Gets the minimum value of this gradient condition. |
Deprecated methods
Method | Return type | Brief description |
---|---|---|
String | Gets the color set for the maximum value of this gradient condition. | |
String | Gets the color set for the mid-point value of this gradient condition. | |
String | Gets 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. Returns null
if the color hasn't been set.
Return
[Color](/apps-script/reference/spreadsheet/color)
— The color set for the maximum value of this gradient condition or null
.
getMaxType()
Gets the interpolation type for the maximum value of this gradient condition. Returns null
if the gradient max type hasn't been set.
Return
[InterpolationType](/apps-script/reference/spreadsheet/interpolation-type)
— the interpolation type for the maximum value of this gradient condition or null
getMaxValue()
Gets the max value of this gradient condition. Returns an empty string if the [InterpolationType](/apps-script/reference/spreadsheet/interpolation-type)
is MAX
or if the max value hasn't been set.
Return
String
— the maximum value if specified or an empty string
getMidColorObject()
Gets the color set for the midpoint value of this gradient condition. Returns null
if the color hasn't been set.
Return
[Color](/apps-script/reference/spreadsheet/color)
— The color set for the midpoint value of this gradient condition or null
.
getMidType()
Gets the interpolation type for the mid-point value of this gradient condition. Returns null
if the gradient mid type hasn't been set.
Return
[InterpolationType](/apps-script/reference/spreadsheet/interpolation-type)
— the interpolation type for the mid-point value of this gradient condition or null
getMidValue()
Gets the mid-point value of this gradient condition. Returns an empty string if the gradient mid value hasn't been set.
Return
String
— the mid-point value or an empty string
getMinColorObject()
Gets the color set for the minimum value of this gradient condition. Returns null
if the color hasn't been set.
Return
[Color](/apps-script/reference/spreadsheet/color)
— The color set for the minimum value of this gradient condition or null
.
getMinType()
Gets the interpolation type for the minimum value of this gradient condition. Returns null
if the gradient min type hasn't been set.
Return
[InterpolationType](/apps-script/reference/spreadsheet/interpolation-type)
— the interpolation type for the minimum value of this gradient condition or null
getMinValue()
Gets the minimum value of this gradient condition. Returns an empty string if the [InterpolationType](/apps-script/reference/spreadsheet/interpolation-type)
is MIN
or if the min value hasn't been set.
Return
String
— the minimum value if specified or an empty string
Deprecated methods
getMaxColor()
getMaxColor()
Deprecated. Replaced by [getMaxColorObject()](#getMaxColorObject%28%29)
Gets the color set for the maximum value of this gradient condition. Returns an empty string if the color hasn't been set.
Return
String
— The color set for the maximum value of this gradient condition or an empty string.
getMidColor()
getMidColor()
Deprecated. Replaced by [getMidColorObject()](#getMidColorObject%28%29)
Gets the color set for the mid-point value of this gradient condition. Returns an empty string if the color hasn't been set.
Return
String
— The color set for the midpoint value of this gradient condition or an empty string.
getMinColor()
getMinColor()
Deprecated. Replaced by [getMinColorObject()](#getMinColorObject%28%29)
Gets the color set for the minimum value of this gradient condition. Returns an empty string if the 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 the Creative Commons Attribution 4.0 License, and code samples are licensed under the Apache 2.0 License. For details, see the Google Developers Site Policies. Java is a registered trademark of Oracle and/or its affiliates.
Last updated 2024-12-02 UTC.