Example:
# Adds an empty conditional formatting workbook = Workbook() sheet = workbook.getWorksheets().get(0) index = sheet.getConditionalFormattings().add() fcs = sheet.getConditionalFormattings().get(index) # Sets the conditional format range. ca = CellArea() ca.StartRow = 0 ca.EndRow = 0 ca.StartColumn = 0 ca.EndColumn = 0 fcs.addArea(ca) ca = CellArea() ca.StartRow = 1 ca.EndRow = 1 ca.StartColumn = 1 ca.EndColumn = 1 fcs.addArea(ca) # Adds condition. conditionIndex = fcs.addCondition(FormatConditionType.CELL_VALUE, OperatorType.BETWEEN, "=A2", "100") # Adds condition. conditionIndex2 = fcs.addCondition(FormatConditionType.CELL_VALUE, OperatorType.BETWEEN, "50", "100") # Sets the background color. fc = fcs.get(conditionIndex) fc.getStyle().setBackgroundColor(Color.getRed()) # Saving the Excel file workbook.save("Book1.xls")
Property Getters/Setters Summary | ||
---|---|---|
method | getCount() | |
Gets the count of the conditions.
|
||
method | getRangeCount() | |
Gets count of conditionally formatted ranges.
|
||
method | get(index) | |
Gets the formatting condition by index.
|
Method Summary | ||
---|---|---|
method | add(cellArea, type, operatorType, formula1, 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 formatting.
|
||
method | addArea(cellArea) | |
Adds a conditional formatted cell range.
|
||
method | addCondition(type) | |
Add a format condition.
|
||
method | addCondition(type, operatorType, formula1, formula2) | |
Adds a formatting condition.
|
||
method | getCellArea(index) | |
Gets the conditional formatted cell range by index.
|
||
method | removeArea(index) | |
Removes conditional formatted cell range by index.
|
||
method | removeArea(startRow, startColumn, totalRows, totalColumns) | |
Remove conditional formatting int the range.
|
||
method | removeCondition(index) | |
Removes the formatting condition by index.
|
int getCount()
int getRangeCount()
FormatCondition get(index)
index
- the index of the formatting condition to return.int[] add(cellArea, type, operatorType, formula1, formula2)
cellArea: CellArea
- Conditional formatted cell range.type: int
- A operatorType: int
- A formula1: String
- The value or expression associated with conditional formatting.formula2: String
- The value or expression associated with conditional formattingint addArea(cellArea)
cellArea: CellArea
- Conditional formatted cell range.int addCondition(type, operatorType, formula1, formula2)
type: int
- A operatorType: int
- A formula1: String
- The value or expression associated with conditional 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: String
- The value or expression associated with conditional formatting.
The input format is same with formula1int addCondition(type)
type: int
- A CellArea getCellArea(index)
index: int
- the index of the conditional formatted cell range.removeArea(index)
index: int
- The index of the conditional formatted cell range to be removed.boolean removeArea(startRow, startColumn, totalRows, totalColumns)
startRow: int
- The startRow of the range.startColumn: int
- The startColumn of the range.totalRows: int
- The number of rows of the range.totalColumns: int
- The number of columns of the range.removeCondition(index)
index: int
- The index of the formatting condition to be removed.