[]
        
(Showing Draft Content)

IColorScale

Interface IColorScale


public interface IColorScale
Represents a color scale conditional formatting rule.

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"));
 
  • Method Summary

    Modifier and Type
    Method
    Description
    void
    Deletes this conditional format.
    void
    Generates the conditional format from the JSON string.
    Returns an IRange object that specifies the cell range to which the formatting rule is applied.
    Gets the color scale criteria collection.
    int
    Returns the priority value of the conditional formatting rule.
    boolean
    Returns a boolean value that determines if additional formatting rules on the cell should be evaluated if the current rule evaluates to True.
    Returns the type of this conditional format.
    void
    Sets an IRange object that specifies the cell range to which the formatting rule is applied.
    void
    Sets the priority value for this conditional formatting rule to 1 so that it will be evaluated before all other rules on the worksheet.
    void
    Sets the evaluation order for this conditional formatting rule so it is evaluated after all other rules on the worksheet.
    void
    setPriority(int value)
    Sets the priority value of the conditional formatting rule.
    Generates a JSON string from the conditional format.
  • Method Details

    • getAppliesTo

      IRange getAppliesTo()
      Returns an 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();
       
      Returns:
      The IRange object that specifies the cell range to which the formatting rule is applied.
    • setAppliesTo

      void setAppliesTo(IRange value)
      Sets an 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"));
       
      Parameters:
      value - The IRange object that specifies the cell range to which the formatting rule is applied.
    • getColorScaleCriteria

      IColorScaleCriteria getColorScaleCriteria()
      Gets the color scale criteria collection.

      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());
       
      Returns:
      The collection of threshold criteria for the color scale conditional format.
    • getPriority

      int getPriority()
      Returns the priority value of the conditional formatting rule.

      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();
       
      Returns:
      The priority value of the conditional formatting rule.
    • setPriority

      void setPriority(int value)
      Sets the priority value of the conditional formatting rule.

      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);
       
      Parameters:
      value - The priority value of the conditional formatting rule.
    • getStopIfTrue

      boolean getStopIfTrue()
      Returns a boolean value that determines if additional formatting rules on the cell should be evaluated if the current rule evaluates to True.

      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();
       
      Returns:
      true if additional formatting rules on the cell should not be evaluated after the current rule evaluates to true; otherwise, false.
    • getType

      Returns the type of this conditional format.

      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();
       
      Returns:
      The type of this conditional format.
    • delete

      void delete()
      Deletes this conditional format.

      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();
       
    • setFirstPriority

      void setFirstPriority()
      Sets the priority value for this conditional formatting rule to 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();
       
    • setLastPriority

      void setLastPriority()
      Sets the evaluation order for this conditional formatting rule so it is evaluated after all other rules on the worksheet.

      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();
       
    • fromJson

      void fromJson(String json)
      Generates the conditional format from the JSON string.

      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);
       
      Parameters:
      json - The JSON string that defines the color scale conditional format.
      Throws:
      IllegalStateException - if the JSON string does not describe a color scale conditional format.
    • toJson

      String toJson()
      Generates a JSON string from the 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();
       
      Returns:
      The conditional format JSON string.