[]
A color scale rule applies a gradient of colors to cells to indicate relative differences in their values. Use this interface to access the range the rule applies to, configure its threshold criteria, and control its evaluation priority among other conditional formatting rules.
IRange range = worksheet.getRange("A1:A5");
range.setValue(new Object[][] {{10}, {30}, {50}, {70}, {90}});
IColorScale colorScale = range.getFormatConditions().addColorScale(ColorScaleType.TwoColorScale);
colorScale.getColorScaleCriteria().get(0).getFormatColor().setColor(Color.GetRed());
colorScale.setAppliesTo(worksheet.getRange("B1:B5"));
voiddelete()voidIRange object that specifies the cell range to which the formatting rule is applied.intbooleangetType()voidsetAppliesTo(IRange value) IRange object that specifies the cell range to which the formatting rule is applied.void1 so that it will be evaluated before all other rules on the worksheet.voidvoidsetPriority(int value) toJson()IRange object that specifies the cell range to which the formatting rule is applied. Use setAppliesTo(IRange) to change the range associated with this color scale conditional formatting rule.
IRange range = worksheet.getRange("A1:A5");
range.setValue(new Object[][] {{10}, {30}, {50}, {70}, {90}});
IColorScale colorScale = range.getFormatConditions().addColorScale(ColorScaleType.TwoColorScale);
IRange appliesTo = colorScale.getAppliesTo();
IRange object that specifies the cell range to which the formatting rule is applied.IRange object that specifies the cell range to which the formatting rule is applied. Use this method to move an existing color scale conditional formatting rule to a different range.
IRange range = worksheet.getRange("A1:A5");
range.setValue(new Object[][] {{10}, {30}, {50}, {70}, {90}});
IColorScale colorScale = range.getFormatConditions().addColorScale(ColorScaleType.TwoColorScale);
colorScale.setAppliesTo(worksheet.getRange("B1:B5"));
value - The IRange object that specifies the cell range to which the formatting rule is applied.Returns an IColorScaleCriteria object, which is a collection of individual IColorScaleCriterion objects. Each criterion specifies the type, value, and color of a threshold used by the color scale conditional format.
IRange range = worksheet.getRange("A1:A5");
range.setValue(new Object[][] {{10}, {30}, {50}, {70}, {90}});
IColorScale colorScale = range.getFormatConditions().addColorScale(ColorScaleType.TwoColorScale);
IColorScaleCriteria criteria = colorScale.getColorScaleCriteria();
criteria.get(0).getFormatColor().setColor(Color.GetRed());
The priority determines the order of evaluation when multiple conditional formatting rules exist in a worksheet. A lower priority value indicates that the rule is evaluated earlier.
Priority values are unique within a worksheet. When the priority of a rule is changed by using setPriority(int), the priority values of other rules on the worksheet may be shifted accordingly.
worksheet.getRange("A1:B5").setValue(new Object[][] {{10, 5}, {30, 15}, {20, 25}, {50, 35}, {40, 45}});
IColorScale firstRule = worksheet.getRange("A1:A5").getFormatConditions().addColorScale(ColorScaleType.TwoColorScale);
IColorScale secondRule = worksheet.getRange("B1:B5").getFormatConditions().addColorScale(ColorScaleType.ThreeColorScale);
secondRule.setPriority(1);
int priority = secondRule.getPriority();
The priority determines the order of evaluation when multiple conditional formatting rules exist in a worksheet. A lower priority value indicates that the rule is evaluated earlier.
worksheet.getRange("A1:B5").setValue(new Object[][] {{10, 5}, {30, 15}, {20, 25}, {50, 35}, {40, 45}});
IColorScale firstRule = worksheet.getRange("A1:A5").getFormatConditions().addColorScale(ColorScaleType.TwoColorScale);
IColorScale secondRule = worksheet.getRange("B1:B5").getFormatConditions().addColorScale(ColorScaleType.ThreeColorScale);
secondRule.setPriority(1);
value - The priority value of the conditional formatting rule.If this method returns true, later conditional formatting rules are not evaluated for cells where this color scale rule evaluates to true. If it returns false, subsequent rules can continue to be evaluated.
IRange range = worksheet.getRange("A1:A5");
range.setValue(new Object[][] {{10}, {30}, {50}, {70}, {90}});
IColorScale colorScale = range.getFormatConditions().addColorScale(ColorScaleType.TwoColorScale);
boolean stopIfTrue = colorScale.getStopIfTrue();
true if additional formatting rules on the cell should not be evaluated after the current rule evaluates to true; otherwise, false.Use this method to identify the conditional formatting rule category as a FormatConditionType value.
IRange range = worksheet.getRange("A1:A5");
range.setValue(new Object[][] {{10}, {30}, {50}, {70}, {90}});
IColorScale colorScale = range.getFormatConditions().addColorScale(ColorScaleType.TwoColorScale);
FormatConditionType type = colorScale.getType();
Use this method to remove the current color scale conditional formatting rule from its worksheet.
IRange range = worksheet.getRange("A1:A5");
range.setValue(new Object[][] {{10}, {30}, {50}, {70}, {90}});
IColorScale colorScale = range.getFormatConditions().addColorScale(ColorScaleType.TwoColorScale);
colorScale.delete();
1 so that it will be evaluated before all other rules on the worksheet. Use this method to move the current color scale rule to the highest evaluation priority among the worksheet's conditional formatting rules.
IRange range = worksheet.getRange("A1:A5");
range.setValue(new Object[][] {{10}, {30}, {50}, {70}, {90}});
range.getFormatConditions().addColorScale(ColorScaleType.TwoColorScale);
IColorScale colorScale = range.getFormatConditions().addColorScale(ColorScaleType.ThreeColorScale);
colorScale.setFirstPriority();
Use this method to move the current color scale rule to the lowest evaluation priority among the conditional formatting rules in the worksheet.
worksheet.getRange("A1:B5").setValue(new Object[][] {
{10, 20}, {30, 40}, {50, 60}, {70, 80}, {90, 100}
});
IColorScale firstRule = worksheet.getRange("A1:A5").getFormatConditions()
.addColorScale(ColorScaleType.TwoColorScale);
IColorScale secondRule = worksheet.getRange("B1:B5").getFormatConditions()
.addColorScale(ColorScaleType.TwoColorScale);
secondRule.setLastPriority();
Uses the specified JSON content to update this color scale rule. The JSON is typically generated by toJson() from another IColorScale instance.
IRange range = worksheet.getRange("A1:A5");
range.setValue(new Object[][] {{10}, {30}, {50}, {70}, {90}});
String json = "{\"ranges\":[{\"row\":0,\"col\":1,\"rowCount\":5,\"colCount\":1}],\"priority\":1,\"ruleType\":10,\"minType\":1,\"minValue\":null,\"minColor\":\"rgb(255,0,0)\",\"maxType\":2,\"maxValue\":null,\"maxColor\":\"rgb(255,239,156)\"}";
IColorScale colorScale = worksheet.getRange("B1:B5").getFormatConditions().addColorScale(ColorScaleType.TwoColorScale);
colorScale.fromJson(json);
json - The JSON string that defines the color scale conditional format.IllegalStateException - if the JSON string does not describe a color scale conditional format.The returned string represents the current color scale conditional formatting rule and can be used with fromJson(String) to recreate the rule.
IRange range = worksheet.getRange("A1:A5");
range.setValue(new Object[][] {{10}, {30}, {50}, {70}, {90}});
IColorScale colorScale = range.getFormatConditions().addColorScale(ColorScaleType.TwoColorScale);
String json = colorScale.toJson();