For performance reasons, this class keeps a cache of all previously evaluated rules and cells.
Be sure to call clearAllCachedFormats() if any conditional formats are modified, added, or deleted,
and clearAllCachedValues() whenever cell values change.
| Modifier and Type | Field and Description |
|---|---|
| private final Map | formats
All the underlying structures, for both HSSF and XSSF, repeatedly go to the raw bytes/XML for the different pieces used in the ConditionalFormatting* structures. |
| private final Map | values
Evaluating rules for cells in their region(s) is expensive, so we want to cache them, and empty/reevaluate the cache when values change. |
| private final Workbook | |
| private final WorkbookEvaluator |
| Access | Constructor and Description |
|---|---|
| public |
| Modifier and Type | Method and Description |
|---|---|
| public void | clearAllCachedFormats()
Call this whenever rules are added, reordered, or removed, or a rule formula is changed (not the formula inputs but the formula expression itself) |
| public void | clearAllCachedValues()
Call this whenever cell values change in the workbook, so condional formats are re-evaluated for all cells. |
| public List | Returns: Unmodifiable List ofEvaluationConditionalFormatRules that apply to the current cell value,
in priority order, as evaluated by Excel (smallest priority # for XSSF, definition order for HSSF),
or null if none applyNote if no sheet name is specified, this uses the workbook active sheet This checks all applicable |
| public List | Returns: Unmodifiable List ofEvaluationConditionalFormatRules that apply to the current cell value,
in priority order, as evaluated by Excel (smallest priority # for XSSF, definition order for HSSF),
or null if none applyThe cell to look for cell)This checks all applicable |
| public List | Returns: unmodifiable list of all Conditional format rules for the given sheet, if anyThe name of the sheet to look at sheetName)Retrieve all formatting rules for the sheet with the given name. |
| public List | Returns: unmodifiable list of all Conditional format rules for the given sheet, if anyThe sheet to look at sheet)Retrieve all formatting rules for the given sheet. |
| public List | Returns: unmodifiable List of all cells in the rule's region matching the rule's conditioncontaining the rule sheet, int of the conditionalFormattingIndex, int ConditionalFormatting instance in the sheet's arrayof the ruleIndex)ConditionalFormattingRule instance within the ConditionalFormattingConditional formatting rules can apply only to cells in the sheet to which they are attached. |
| public List | Returns: unmodifiable List of all cells in the rule's region matching the rule's conditionThe rule to look at rule)Retrieve all cells where the given formatting rule evaluates to true. |
| public static CellReference | |
| protected List | |
| protected WorkbookEvaluator |
| formats | back to summary |
|---|---|
| private final Map<String, List<EvaluationConditionalFormatRule>> formats All the underlying structures, for both HSSF and XSSF, repeatedly go to the raw bytes/XML for the different pieces used in the ConditionalFormatting* structures. That's highly inefficient, and can cause significant lag when checking formats for large workbooks. Instead we need a cached version that is discarded when definitions change. Sheets don't implement equals, and since its an interface, there's no guarantee instances won't be recreated on the fly by some implementation. So we use sheet name. | |
| values | back to summary |
|---|---|
| private final Map<CellReference, List<EvaluationConditionalFormatRule>> values Evaluating rules for cells in their region(s) is expensive, so we want to cache them, and empty/reevaluate the cache when values change. Rule lists are in priority order, as evaluated by Excel (smallest priority # for XSSF, definition order for HSSF) CellReference implements equals(). | |
| workbook | back to summary |
|---|---|
| private final Workbook workbook | |
| workbookEvaluator | back to summary |
|---|---|
| private final WorkbookEvaluator workbookEvaluator | |
| ConditionalFormattingEvaluator | back to summary |
|---|---|
| public ConditionalFormattingEvaluator(Workbook wb, WorkbookEvaluatorProvider provider) | |
| clearAllCachedFormats | back to summary |
|---|---|
| public void clearAllCachedFormats() Call this whenever rules are added, reordered, or removed, or a rule formula is changed (not the formula inputs but the formula expression itself) | |
| clearAllCachedValues | back to summary |
|---|---|
| public void clearAllCachedValues() Call this whenever cell values change in the workbook, so condional formats are re-evaluated for all cells. Todo eventually this should work like | |
| getConditionalFormattingForCell | back to summary |
|---|---|
| public List This checks all applicable Most cells will have zero or one applied rule, but it is possible to define multiple rules that apply at the same time to the same cell, thus the List result.
Note that to properly apply conditional rules, care must be taken to offset the base
formula by the relative position of the current cell, or the wrong value is checked.
This is handled by
If the cell exists and is a formula cell, its cached value may be used for rule evaluation, so
make sure it is up to date. If values have changed, it is best to call
| |
| getConditionalFormattingForCell | back to summary |
|---|---|
| public List This checks all applicable Most cells will have zero or one applied rule, but it is possible to define multiple rules that apply at the same time to the same cell, thus the List result.
Note that to properly apply conditional rules, care must be taken to offset the base
formula by the relative position of the current cell, or the wrong value is checked.
This is handled by
If the cell exists and is a formula cell, its cached value may be used for rule evaluation, so
make sure it is up to date. If values have changed, it is best to call
| |
| getFormatRulesForSheet | back to summary |
|---|---|
| public List Retrieve all formatting rules for the sheet with the given name.
| |
| getFormatRulesForSheet | back to summary |
|---|---|
| public List Retrieve all formatting rules for the given sheet.
| |
| getMatchingCells | back to summary |
|---|---|
| public List Conditional formatting rules can apply only to cells in the sheet to which they are attached. The POI data model does not have a back-reference to the owning sheet, so it must be passed in separately. We could overload this with convenience methods taking a sheet name and sheet index as well.
| |
| getMatchingCells | back to summary |
|---|---|
| public List Retrieve all cells where the given formatting rule evaluates to true.
| |
| getRef | back to summary |
|---|---|
| public static CellReference getRef(Cell cell) | |
| getRules | back to summary |
|---|---|
| protected List lazy load by sheet since reading can be expensive
| |
| getWorkbookEvaluator | back to summary |
|---|---|
| protected WorkbookEvaluator getWorkbookEvaluator() | |