public class FormatConditionCollection
Example:
//Adds an empty conditional formatting
int index = sheet.getConditionalFormattings().add();
FormatConditionCollection fcs = sheet.getConditionalFormattings().get(index);
//Sets the conditional format range.
CellArea ca = new CellArea();
ca.StartRow = 0;
ca.EndRow = 0;
ca.StartColumn = 0;
ca.EndColumn = 0;
fcs.addArea(ca);
ca = new CellArea();
ca.StartRow = 1;
ca.EndRow = 1;
ca.StartColumn = 1;
ca.EndColumn = 1;
fcs.addArea(ca);
//Adds condition.
int conditionIndex = fcs.addCondition(FormatConditionType.CELL_VALUE, OperatorType.BETWEEN, "=A2", "100");
//Adds condition.
int conditionIndex2 = fcs.addCondition(FormatConditionType.CELL_VALUE, OperatorType.BETWEEN, "50", "100");
//Sets the background color.
FormatCondition fc = fcs.get(conditionIndex);
fc.getStyle().setBackgroundColor(Color.getRed());
//Saving the Excel file
workbook.save("C:\\output.xls");
Property Getters/Setters Summary | ||
---|---|---|
int | getCount() | |
Gets the count of the conditions.
|
||
int | getRangeCount() | |
Gets count of conditionally formatted ranges.
|
||
FormatCondition | get(int index) | |
Gets the formatting conidition by index.
|
Method Summary | ||
---|---|---|
int[] | add(CellArea cellArea, int type, int operatorType, java.lang.String formula1, java.lang.String formula2) | |
Adds a formatting condition and effected cell rang to the FormatConditions
The FormatConditions can contain up to three conditional formats.
References to the other sheets are not allowed in the formulas of conditional formattin
|
||
int | addArea(CellArea cellArea) | |
Adds a conditional formatted cell range.
|
||
int | addCondition(int type) | |
Add a format condition.
|
||
int | addCondition(int type, int operatorType, java.lang.String formula1, java.lang.String formula2) | |
Adds a formatting condition.
|
||
CellArea | getCellArea(int index) | |
Gets the conditional formatted cell range by index.
|
||
void | removeArea(int index) | |
Removes conditional formatted cell range by index.
|
||
boolean | removeArea(int startRow, int startColumn, int totalRows, int totalColumns) | |
Remove conditional formatting int the range.
|
||
void | removeCondition(int index) | |
Removes the formatting condition by index.
|
public int getCount()
public int getRangeCount()
public FormatCondition get(int index)
index
- the index of the formatting conidition to return.public int[] add(CellArea cellArea, int type, int operatorType, java.lang.String formula1, java.lang.String formula2)
cellArea
- Conditional formatted cell range.type
- A operatorType
- A formula1
- The value or expression associated with conditional formatting.formula2
- The value or expression associated with conditional formattingpublic int addArea(CellArea cellArea)
cellArea
- Conditional formatted cell range.public int addCondition(int type, int operatorType, java.lang.String formula1, java.lang.String formula2)
type
- A operatorType
- A formula1
- The value or expression associated with conditinal formatting.
If the input value starts with '=', then it will be taken as formula.
Otherwise it will be taken as plain value(text, number, bool).
For text value that starts with '=', user may input it as formula in format: "=\"=...\"".formula2
- The value or expression associated with conditinal formatting. The input format is same with formula1public int addCondition(int type)
type
- A public CellArea getCellArea(int index)
index
- the index of the coditional formatted cell range.public void removeArea(int index)
index
- The index of the conditional formatted cell range to be removed.public boolean removeArea(int startRow, int startColumn, int totalRows, int totalColumns)
startRow
- The startRow of the range.startColumn
- The startColumn of the range.totalRows
- The number of rows of the range.totalColumns
- The number of columns of the range.public void removeCondition(int index)
index
- The index of the formatting condition to be removed.