Class ExcelConditionalRule

java.lang.Object
io.github.dornol.excelkit.excel.ExcelConditionalRule

public class ExcelConditionalRule extends Object
Builder for conditional formatting rules to apply to Excel sheets.

Supports cell-value-based rules, data bars, and icon sets.


 ExcelWriter.<Product>create()
     .column("Price", Product::getPrice, c -> c.type(ExcelDataType.INTEGER))
     .conditionalFormatting(cf -> cf
         .columns(1)
         .greaterThan("1000", ExcelColor.LIGHT_RED)
         .lessThan("100", ExcelColor.LIGHT_GREEN))
     .conditionalFormatting(cf -> cf
         .columns(1)
         .dataBar(ExcelColor.BLUE))
     .conditionalFormatting(cf -> cf
         .columns(1)
         .iconSet(ExcelConditionalRule.IconSetType.ARROWS_3))
     .write(stream)
     .write(out);
 
Since:
0.6.0
  • Constructor Details

    • ExcelConditionalRule

      public ExcelConditionalRule()
      Creates a new conditional rule builder.
  • Method Details

    • columns

      public ExcelConditionalRule columns(int... indices)
      Sets the columns to apply conditional formatting to (0-based indices).
      Parameters:
      indices - 0-based column indices
      Returns:
      this rule for chaining
    • startRow

      public ExcelConditionalRule startRow(int startRow)
      Sets the starting data row (0-based). If not set, defaults to the row after the header.
      Parameters:
      startRow - 0-based starting row
      Returns:
      this rule for chaining
    • greaterThan

      public ExcelConditionalRule greaterThan(String value, ExcelColor bgColor)
      Adds a rule: cell value greater than the given value.
      Parameters:
      value - the comparison value
      bgColor - the background color to apply
      Returns:
      this rule for chaining
    • greaterThanOrEqual

      public ExcelConditionalRule greaterThanOrEqual(String value, ExcelColor bgColor)
      Adds a rule: cell value greater than or equal to the given value.
      Parameters:
      value - the comparison value
      bgColor - the background color to apply
      Returns:
      this rule for chaining
    • lessThan

      public ExcelConditionalRule lessThan(String value, ExcelColor bgColor)
      Adds a rule: cell value less than the given value.
      Parameters:
      value - the comparison value
      bgColor - the background color to apply
      Returns:
      this rule for chaining
    • lessThanOrEqual

      public ExcelConditionalRule lessThanOrEqual(String value, ExcelColor bgColor)
      Adds a rule: cell value less than or equal to the given value.
      Parameters:
      value - the comparison value
      bgColor - the background color to apply
      Returns:
      this rule for chaining
    • equalTo

      public ExcelConditionalRule equalTo(String value, ExcelColor bgColor)
      Adds a rule: cell value equal to the given value.
      Parameters:
      value - the comparison value
      bgColor - the background color to apply
      Returns:
      this rule for chaining
    • notEqualTo

      public ExcelConditionalRule notEqualTo(String value, ExcelColor bgColor)
      Adds a rule: cell value not equal to the given value.
      Parameters:
      value - the comparison value
      bgColor - the background color to apply
      Returns:
      this rule for chaining
    • between

      public ExcelConditionalRule between(String value1, String value2, ExcelColor bgColor)
      Adds a rule: cell value between the given values (inclusive).
      Parameters:
      value1 - the lower bound
      value2 - the upper bound
      bgColor - the background color to apply
      Returns:
      this rule for chaining
    • notBetween

      public ExcelConditionalRule notBetween(String value1, String value2, ExcelColor bgColor)
      Adds a rule: cell value not between the given values.
      Parameters:
      value1 - the lower bound
      value2 - the upper bound
      bgColor - the background color to apply
      Returns:
      this rule for chaining
    • dataBar

      public ExcelConditionalRule dataBar(ExcelColor color)
      Adds a data bar conditional formatting with the specified fill color.

      Data bars display a gradient bar in each cell proportional to the cell's value.

      Parameters:
      color - the fill color of the data bar
      Returns:
      this rule for chaining
      Since:
      0.9.2
    • dataBar

      public ExcelConditionalRule dataBar(ExcelColor minColor, ExcelColor maxColor)
      Adds a 2-color gradient data bar conditional formatting.

      The bar gradient transitions from minColor (lowest value) to maxColor (highest value).

      Parameters:
      minColor - the color for the minimum value end of the bar
      maxColor - the color for the maximum value end of the bar
      Returns:
      this rule for chaining
      Since:
      0.9.2
    • iconSet

      Adds an icon set conditional formatting.

      Icon sets display icons (arrows, traffic lights, flags, etc.) based on cell values.

      Parameters:
      type - the icon set type
      Returns:
      this rule for chaining
      Since:
      0.9.2