Package io.github.dornol.excelkit.excel
Class ExcelConditionalRule
java.lang.Object
io.github.dornol.excelkit.excel.ExcelConditionalRule
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
-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionstatic enumSupported icon set types for conditional formatting. -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionbetween(String value1, String value2, ExcelColor bgColor) Adds a rule: cell value between the given values (inclusive).columns(int... indices) Sets the columns to apply conditional formatting to (0-based indices).dataBar(ExcelColor color) Adds a data bar conditional formatting with the specified fill color.dataBar(ExcelColor minColor, ExcelColor maxColor) Adds a 2-color gradient data bar conditional formatting.equalTo(String value, ExcelColor bgColor) Adds a rule: cell value equal to the given value.greaterThan(String value, ExcelColor bgColor) Adds a rule: cell value greater than the given value.greaterThanOrEqual(String value, ExcelColor bgColor) Adds a rule: cell value greater than or equal to the given value.Adds an icon set conditional formatting.lessThan(String value, ExcelColor bgColor) Adds a rule: cell value less than the given value.lessThanOrEqual(String value, ExcelColor bgColor) Adds a rule: cell value less than or equal to the given value.notBetween(String value1, String value2, ExcelColor bgColor) Adds a rule: cell value not between the given values.notEqualTo(String value, ExcelColor bgColor) Adds a rule: cell value not equal to the given value.startRow(int startRow) Sets the starting data row (0-based).
-
Constructor Details
-
ExcelConditionalRule
public ExcelConditionalRule()Creates a new conditional rule builder.
-
-
Method Details
-
columns
Sets the columns to apply conditional formatting to (0-based indices).- Parameters:
indices- 0-based column indices- Returns:
- this rule for chaining
-
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
Adds a rule: cell value greater than the given value.- Parameters:
value- the comparison valuebgColor- the background color to apply- Returns:
- this rule for chaining
-
greaterThanOrEqual
Adds a rule: cell value greater than or equal to the given value.- Parameters:
value- the comparison valuebgColor- the background color to apply- Returns:
- this rule for chaining
-
lessThan
Adds a rule: cell value less than the given value.- Parameters:
value- the comparison valuebgColor- the background color to apply- Returns:
- this rule for chaining
-
lessThanOrEqual
Adds a rule: cell value less than or equal to the given value.- Parameters:
value- the comparison valuebgColor- the background color to apply- Returns:
- this rule for chaining
-
equalTo
Adds a rule: cell value equal to the given value.- Parameters:
value- the comparison valuebgColor- the background color to apply- Returns:
- this rule for chaining
-
notEqualTo
Adds a rule: cell value not equal to the given value.- Parameters:
value- the comparison valuebgColor- the background color to apply- Returns:
- this rule for chaining
-
between
Adds a rule: cell value between the given values (inclusive).- Parameters:
value1- the lower boundvalue2- the upper boundbgColor- the background color to apply- Returns:
- this rule for chaining
-
notBetween
Adds a rule: cell value not between the given values.- Parameters:
value1- the lower boundvalue2- the upper boundbgColor- the background color to apply- Returns:
- this rule for chaining
-
dataBar
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
Adds a 2-color gradient data bar conditional formatting.The bar gradient transitions from
minColor(lowest value) tomaxColor(highest value).- Parameters:
minColor- the color for the minimum value end of the barmaxColor- 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
-