[]
        
(Showing Draft Content)

IDataBar

Interface IDataBar


public interface IDataBar
Represents a data bar conditional formatting rule.

Applying a data bar to a range helps visualize each cell value relative to the other values in the same range. Use this interface to configure the appearance and behavior of a data bar rule, such as its fill, color, axis, direction, and value display.


 worksheet.getRange("A1:A5").setValue(new Object[][] {
     {1}, {2}, {3}, {4}, {5}
 });
 IDataBar dataBar = worksheet.getRange("A1:A5").getFormatConditions().addDatabar();
 dataBar.setBarFillType(DataBarFillType.Solid);
 dataBar.getBarColor().setColor(Color.GetGreen());
 dataBar.setShowValue(false);
 
  • Method Summary

    Modifier and Type
    Method
    Description
    void
    Deletes this data bar conditional formatting rule.
    void
    Loads the data bar conditional format from a JSON string.
    Gets the cell range to which this data bar conditional formatting rule is applied.
    Gets the color of the axis for cells with conditional formatting as data bars.
    Gets the axis position of the data bars in this conditional formatting rule.
    Gets an object that specifies the border of a data bar.
    Gets the color of the bars in this data bar conditional formatting rule.
    Gets how a data bar is filled with color.
    Gets the display direction of the data bar.
    Gets the IConditionValue that specifies how the longest bar is evaluated for a data bar conditional format.
    Gets the IConditionValue that specifies how the shortest bar is evaluated for a data bar conditional format.
    Gets the negative bar format settings for this data bar conditional formatting rule.
    int
    Gets the length of the longest data bar as a percentage of the cell width.
    int
    Gets the length of the shortest data bar as a percentage of the cell width.
    int
    Gets the priority value of the conditional formatting rule.
    boolean
    Gets whether cell values are displayed when the data bar conditional format is applied.
    boolean
    Gets whether additional conditional formatting rules on the cell are evaluated after this data bar rule evaluates to true.
    Gets the type of this conditional format.
    void
    Sets the cell range to which this data bar conditional formatting rule is applied.
    void
    Sets the axis position of the data bars in this conditional formatting rule.
    void
    Sets how a data bar is filled with color.
    void
    Sets the display direction of the data bar.
    void
    Sets the priority value for this conditional formatting rule to 1 so that it is evaluated before all other rules on the worksheet.
    void
    Sets the evaluation order for this data bar rule so it is evaluated after all other rules on the worksheet.
    void
    setPercentMax(int value)
    Sets an Integer value that specifies the length of the longest data bar as a percentage of cell width.
    void
    setPercentMin(int value)
    Sets an Integer value that specifies the length of the shortest data bar as a percentage of cell width.
    void
    setPriority(int value)
    Sets the priority value of the conditional formatting rule.
    void
    setShowValue(boolean value)
    Sets whether cell values are displayed when the data bar conditional format is applied.
    Generates a JSON string from the data bar rule.
  • Method Details

    • getAppliesTo

      IRange getAppliesTo()
      Gets the cell range to which this data bar conditional formatting rule is applied.

      Use this method to retrieve the IRange associated with the current data bar rule.

      
       worksheet.getRange("A1:A3").setValue(new Object[][] {{10}, {30}, {20}});
       IDataBar dataBar = worksheet.getRange("A1:A3").getFormatConditions().addDatabar();
       IRange appliesTo = dataBar.getAppliesTo();
       String address = appliesTo.getAddress();
       
      Returns:
      The IRange to which this data bar rule is applied.
    • setAppliesTo

      void setAppliesTo(IRange value)
      Sets the cell range to which this data bar conditional formatting rule is applied.

      Use this method to change the IRange associated with the current data bar rule.

      
       worksheet.getRange("A1:A3").setValue(new Object[][] {{10}, {30}, {20}});
       IDataBar dataBar = worksheet.getRange("A1:A3").getFormatConditions().addDatabar();
       dataBar.setAppliesTo(worksheet.getRange("B1:B3"));
       IRange appliesTo = dataBar.getAppliesTo();
       
      Parameters:
      value - The IRange to which this data bar rule is applied. Must not be null.
    • getAxisColor

      IFormatColor getAxisColor()
      Gets the color of the axis for cells with conditional formatting as data bars.

      Returns an IFormatColor object that you can use to read or modify the axis color of the data bar rule.

      
       worksheet.getRange("A1:A3").setValue(new Object[][] {{-10}, {0}, {20}});
       IDataBar dataBar = worksheet.getRange("A1:A3").getFormatConditions().addDatabar();
       dataBar.setAxisPosition(DataBarAxisPosition.Automatic);
       IFormatColor axisColor = dataBar.getAxisColor();
       axisColor.setColor(Color.GetBlue());
       
      Returns:
      An IFormatColor object that represents the axis color of the data bar rule.
    • getAxisPosition

      DataBarAxisPosition getAxisPosition()
      Gets the axis position of the data bars in this conditional formatting rule.

      The axis position controls how positive and negative data bars are separated within each cell. Use DataBarAxisPosition.Automatic to place the axis based on the values in the range, DataBarAxisPosition.Midpoint to keep the axis centered, or DataBarAxisPosition.None to hide the axis.

      
       worksheet.getRange("A1:A3").setValue(new Object[][] {{-10}, {0}, {20}});
       IDataBar dataBar = worksheet.getRange("A1:A3").getFormatConditions().addDatabar();
       dataBar.setAxisPosition(DataBarAxisPosition.Automatic);
       DataBarAxisPosition axisPosition = dataBar.getAxisPosition();
       
      Returns:
      A DataBarAxisPosition value that indicates where the data bar axis is displayed.
    • setAxisPosition

      void setAxisPosition(DataBarAxisPosition value)
      Sets the axis position of the data bars in this conditional formatting rule.

      The axis position controls how positive and negative data bars are separated within each cell. Use DataBarAxisPosition.Automatic to place the axis based on the values in the range, DataBarAxisPosition.Midpoint to keep the axis centered, or DataBarAxisPosition.None to hide the axis.

      
       worksheet.getRange("A1:A3").setValue(new Object[][] {{-10}, {0}, {20}});
       IDataBar dataBar = worksheet.getRange("A1:A3").getFormatConditions().addDatabar();
       dataBar.setAxisPosition(DataBarAxisPosition.Midpoint);
       DataBarAxisPosition axisPosition = dataBar.getAxisPosition();
       
      Parameters:
      value - The DataBarAxisPosition value that specifies where the data bar axis is displayed.
    • getBarBorder

      IDataBarBorder getBarBorder()
      Gets an object that specifies the border of a data bar.

      Use the returned IDataBarBorder object to configure the border appearance of the current data bar, such as its border type and color.

      
       worksheet.getRange("A1:A5").setValue(new Object[][] {{1}, {2}, {3}, {4}, {5}});
       IDataBar dataBar = worksheet.getRange("A1:A5").getFormatConditions().addDatabar();
       IDataBarBorder border = dataBar.getBarBorder();
       border.setType(DataBarBorderType.Solid);
       
      Returns:
      The IDataBarBorder object that specifies the border of a data bar.
    • getBarColor

      IFormatColor getBarColor()
      Gets the color of the bars in this data bar conditional formatting rule.

      Returns an IFormatColor object that you can use to read or modify the fill color applied to the data bars.

      
       worksheet.getRange("A1:A3").setValue(new Object[][] {{10}, {30}, {20}});
       IDataBar dataBar = worksheet.getRange("A1:A3").getFormatConditions().addDatabar();
       IFormatColor barColor = dataBar.getBarColor();
       barColor.setColor(Color.GetRed());
       
      Returns:
      The color of the bars in this data bar conditional formatting rule.
    • getBarFillType

      DataBarFillType getBarFillType()
      Gets how a data bar is filled with color.

      Returns a DataBarFillType value that indicates whether the data bar uses a solid fill or a gradient fill.

      
       worksheet.getRange("A1:A3").setValue(new Object[][] {{10}, {30}, {20}});
       IDataBar dataBar = worksheet.getRange("A1:A3").getFormatConditions().addDatabar();
       dataBar.setBarFillType(DataBarFillType.Gradient);
       DataBarFillType fillType = dataBar.getBarFillType();
       
      Returns:
      A DataBarFillType value that specifies how a data bar is filled with color.
    • setBarFillType

      void setBarFillType(DataBarFillType value)
      Sets how a data bar is filled with color.

      Use a DataBarFillType value to specify whether the data bar uses a solid fill or a gradient fill.

      
       worksheet.getRange("A1:A3").setValue(new Object[][] {{10}, {30}, {20}});
       IDataBar dataBar = worksheet.getRange("A1:A3").getFormatConditions().addDatabar();
       dataBar.setBarFillType(DataBarFillType.Gradient);
       
      Parameters:
      value - The data bar fill type.
    • getDirection

      DataBarDirection getDirection()
      Gets the display direction of the data bar.

      The returned DataBarDirection value determines whether the data bar follows the current context, is displayed from left to right, or is displayed from right to left.

      
       worksheet.getRange("A1:A3").setValue(new Object[][] {{10}, {20}, {30}});
       IDataBar dataBar = worksheet.getRange("A1:A3").getFormatConditions().addDatabar();
       dataBar.setDirection(DataBarDirection.RightToLeft);
       DataBarDirection direction = dataBar.getDirection();
       
      Returns:
      A DataBarDirection value that specifies the display direction of the data bar.
    • setDirection

      void setDirection(DataBarDirection value)
      Sets the display direction of the data bar.

      Use this method to control whether the data bar is rendered from left to right, from right to left, or according to the worksheet context.

      
       worksheet.getRange("A1:A3").setValue(new Object[][] {{10}, {30}, {20}});
       IDataBar dataBar = worksheet.getRange("A1:A3").getFormatConditions().addDatabar();
       dataBar.setDirection(DataBarDirection.RightToLeft);
       DataBarDirection direction = dataBar.getDirection();
       
      Parameters:
      value - The data bar direction to apply. Must be a valid DataBarDirection value.
    • getMaxPoint

      IConditionValue getMaxPoint()
      Gets the IConditionValue that specifies how the longest bar is evaluated for a data bar conditional format.

      Use the returned object to configure the maximum threshold for the data bar, such as a numeric limit or another supported condition value type.

      
       worksheet.getRange("A1:A3").setValue(new Object[][] {{10}, {20}, {30}});
       IDataBar dataBar = worksheet.getRange("A1:A3").getFormatConditions().addDatabar();
       IConditionValue maxPoint = dataBar.getMaxPoint();
       maxPoint.setType(ConditionValueTypes.Number);
       maxPoint.setValue(30);
       
      Returns:
      The IConditionValue object that specifies how the longest bar is evaluated for a data bar conditional format.
    • getMinPoint

      IConditionValue getMinPoint()
      Gets the IConditionValue that specifies how the shortest bar is evaluated for a data bar conditional format.

      Use the returned object to configure the minimum threshold for the data bar, such as a numeric limit or another supported condition value type.

      
       worksheet.getRange("A1:A3").setValue(new Object[][] {{10}, {20}, {30}});
       IDataBar dataBar = worksheet.getRange("A1:A3").getFormatConditions().addDatabar();
       IConditionValue minPoint = dataBar.getMinPoint();
       minPoint.setType(ConditionValueTypes.Number);
       minPoint.setValue(10);
       
      Returns:
      The IConditionValue object that specifies how the shortest bar is evaluated for a data bar conditional format.
    • getNegativeBarFormat

      INegativeBarFormat getNegativeBarFormat()
      Gets the negative bar format settings for this data bar conditional formatting rule.

      Use the returned INegativeBarFormat object to configure the fill color and border color behavior for negative values in the data bar.

      
       worksheet.getRange("A1:A4").setValue(new Object[][] {{-10}, {-5}, {0}, {20}});
       IDataBar dataBar = worksheet.getRange("A1:A4").getFormatConditions().addDatabar();
       INegativeBarFormat negativeBarFormat = dataBar.getNegativeBarFormat();
       negativeBarFormat.setColorType(DataBarNegativeColorType.Color);
       negativeBarFormat.getColor().setColor(Color.GetRed());
       
      Returns:
      The INegativeBarFormat settings for this data bar conditional formatting rule; see INegativeBarFormat.
    • getPercentMax

      int getPercentMax()
      Gets the length of the longest data bar as a percentage of the cell width.

      Use this property to determine the maximum visual length applied to data bars in the conditional formatting rule.

      
       worksheet.getRange("A1:A3").setValue(new Object[][] {{10}, {30}, {20}});
       IDataBar dataBar = worksheet.getRange("A1:A3").getFormatConditions().addDatabar();
       dataBar.setPercentMax(80);
       int percentMax = dataBar.getPercentMax();
       
      Returns:
      The length of the longest data bar as a percentage of the cell width.
    • setPercentMax

      void setPercentMax(int value)
      Sets an Integer value that specifies the length of the longest data bar as a percentage of cell width.

      Use this property to control the maximum visual length of data bars in the conditional formatting rule.

      
       worksheet.getRange("A1:A3").setValue(new Object[][] {{10}, {30}, {20}});
       IDataBar dataBar = worksheet.getRange("A1:A3").getFormatConditions().addDatabar();
       dataBar.setPercentMax(80);
       
      Parameters:
      value - The percentage of the cell width used for the longest data bar.
    • getPercentMin

      int getPercentMin()
      Gets the length of the shortest data bar as a percentage of the cell width.

      Use this property to determine the minimum visual length applied to data bars in the conditional formatting rule.

      
       worksheet.getRange("A1:A3").setValue(new Object[][] {{10}, {30}, {20}});
       IDataBar dataBar = worksheet.getRange("A1:A3").getFormatConditions().addDatabar();
       dataBar.setPercentMin(15);
       int percentMin = dataBar.getPercentMin();
       
      Returns:
      The length of the shortest data bar as a percentage of the cell width.
    • setPercentMin

      void setPercentMin(int value)
      Sets an Integer value that specifies the length of the shortest data bar as a percentage of cell width.

      Use this method to control the minimum visible length of data bars in the conditional formatting rule.

      
       worksheet.getRange("A1:A3").setValue(new Object[][] {{10}, {30}, {20}});
       IDataBar dataBar = worksheet.getRange("A1:A3").getFormatConditions().addDatabar();
       dataBar.setPercentMin(15);
       int percentMin = dataBar.getPercentMin();
       
      Parameters:
      value - The length of the shortest data bar, expressed as a percentage of the cell width.
    • getPriority

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

      The priority determines the order in which conditional formatting rules are evaluated when multiple rules exist on a worksheet. Priority values are unique within the worksheet, so changing the priority of one rule can shift the priority values of other rules.

      
       worksheet.getRange("A1:B3").setValue(new Object[][] {{10, 5}, {30, 15}, {20, 25}});
       IDataBar firstDataBar = worksheet.getRange("A1:A3").getFormatConditions().addDatabar();
       IDataBar secondDataBar = worksheet.getRange("B1:B3").getFormatConditions().addDatabar();
       secondDataBar.setPriority(1);
       int priority = secondDataBar.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 evaluation order when multiple conditional formatting rules exist on a worksheet. The value must be a positive integer between 1 and the total number of conditional formatting rules on the worksheet. Because each rule must have a unique priority, changing the priority of this rule may shift the priority values of other rules on the worksheet.

      
       worksheet.getRange("A1:B3").setValue(new Object[][] {{10, 5}, {30, 15}, {20, 25}});
       IDataBar firstDataBar = worksheet.getRange("A1:A3").getFormatConditions().addDatabar();
       IDataBar secondDataBar = worksheet.getRange("B1:B3").getFormatConditions().addDatabar();
       secondDataBar.setPriority(1);
       
      Parameters:
      value - The priority value of the conditional formatting rule. Must be a positive integer between 1 and the total number of conditional formatting rules on the worksheet.
    • getShowValue

      boolean getShowValue()
      Gets whether cell values are displayed when the data bar conditional format is applied.

      This property indicates whether the original cell values remain visible together with the data bars.

      
       worksheet.getRange("A1:A3").setValue(new Object[][] {{10}, {30}, {20}});
       IDataBar dataBar = worksheet.getRange("A1:A3").getFormatConditions().addDatabar();
       dataBar.setShowValue(false);
       boolean showValue = dataBar.getShowValue();
       
      Returns:
      true if cell values are displayed when the data bar conditional format is applied; otherwise, false.
    • setShowValue

      void setShowValue(boolean value)
      Sets whether cell values are displayed when the data bar conditional format is applied.

      Use this property to show or hide the original cell values while keeping the data bars visible.

      
       worksheet.getRange("A1:A3").setValue(new Object[][] {{10}, {30}, {20}});
       IDataBar dataBar = worksheet.getRange("A1:A3").getFormatConditions().addDatabar();
       dataBar.setShowValue(false);
       
      Parameters:
      value - true to display the cell values together with the data bars; otherwise, false.
    • getStopIfTrue

      boolean getStopIfTrue()
      Gets whether additional conditional formatting rules on the cell are evaluated after this data bar rule evaluates to true.

      If this property is true, lower-priority conditional formatting rules continue to be evaluated for the cells to which this data bar applies.

      
       worksheet.getRange("A1:A3").setValue(new Object[][] {{10}, {30}, {20}});
       IDataBar dataBar = worksheet.getRange("A1:A3").getFormatConditions().addDatabar();
       boolean stopIfTrue = dataBar.getStopIfTrue();
       
      Returns:
      true if additional conditional formatting rules on the cell are evaluated after this data bar rule evaluates to; otherwise, false.
    • getType

      Gets the type of this conditional format.

      For a data bar conditional formatting rule, this method returns the corresponding FormatConditionType value, such as FormatConditionType.Databar.

      
       worksheet.getRange("A1:A5").setValue(new Object[][] {{10}, {30}, {20}, {40}, {25}});
       IDataBar dataBar = worksheet.getRange("A1:A5").getFormatConditions().addDatabar();
       FormatConditionType type = dataBar.getType();
       
      Returns:
      The type of this conditional format.
    • delete

      void delete()
      Deletes this data bar conditional formatting rule.

      After this method is called, the data bar is removed from the range to which it applies.

      
       worksheet.getRange("A1:A5").setValue(new Object[][] {{1}, {2}, {3}, {4}, {5}});
       IDataBar dataBar = worksheet.getRange("A1:A5").getFormatConditions().addDatabar();
       dataBar.delete();
       
    • setFirstPriority

      void setFirstPriority()
      Sets the priority value for this conditional formatting rule to 1 so that it is evaluated before all other rules on the worksheet.

      Use this method to move a data bar rule to the highest evaluation priority among the conditional formatting rules on the same worksheet.

      
       worksheet.getRange("A1:B3").setValue(new Object[][] {{10, 5}, {30, 15}, {20, 25}});
       IDataBar firstDataBar = worksheet.getRange("A1:A3").getFormatConditions().addDatabar();
       IDataBar secondDataBar = worksheet.getRange("B1:B3").getFormatConditions().addDatabar();
       firstDataBar.setFirstPriority();
       
    • setLastPriority

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

      Use this method to move the current data bar rule to the end of the worksheet rule priority order.

      
       worksheet.getRange("A1:B3").setValue(new Object[][] {{10, 5}, {30, 15}, {20, 25}});
       IDataBar firstDataBar = worksheet.getRange("A1:A3").getFormatConditions().addDatabar();
       IDataBar secondDataBar = worksheet.getRange("B1:B3").getFormatConditions().addDatabar();
       secondDataBar.setLastPriority();
       
    • fromJson

      void fromJson(String json)
      Loads the data bar conditional format from a JSON string.

      This method replaces the current data bar rule with the rule defined in the specified JSON string. The JSON content is typically generated by toJson().

      
       worksheet.getRange("A1:A3").setValue(new Object[][] {{10}, {30}, {20}});
       IDataBar dataBar = worksheet.getRange("A1:A3").getFormatConditions().addDatabar();
       dataBar.setBarFillType(DataBarFillType.Solid);
       dataBar.getBarColor().setColor(Color.GetGreen());
       dataBar.setShowValue(false);
       String json = dataBar.toJson();
       IDataBar copiedDataBar = worksheet.getRange("B1:B3").getFormatConditions().addDatabar();
       copiedDataBar.fromJson(json);
       
      Parameters:
      json - The JSON string that defines a data bar conditional format.
      Throws:
      IllegalStateException - if the specified JSON string does not describe a data bar conditional format.
    • toJson

      String toJson()
      Generates a JSON string from the data bar rule.

      Use this method to serialize the current data bar settings so that they can be reused with fromJson(String) or stored for later use.

      
       worksheet.getRange("A1:A3").setValue(new Object[][] {
           {10},
           {30},
           {20}
       });
       IDataBar dataBar = worksheet.getRange("A1:A3").getFormatConditions().addDatabar();
       String json = dataBar.toJson();
       
      Returns:
      A JSON string that represents the current data bar rule.