public class ConditionalFormattingEvaluator
extends java.lang.Object
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.
Constructor and Description |
---|
ConditionalFormattingEvaluator(Workbook wb, WorkbookEvaluatorProvider provider) |
Modifier and Type | Method and Description |
---|---|
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)
(每当添加、重新排序或删除规则或更改规则公式(不是公式输入而是公式表达式本身)时调用此函数)
|
void |
clearAllCachedValues()
Call this whenever cell values change in the workbook, so condional formats are re-evaluated for all cells.
(每当工作簿中的单元格值发生变化时调用此函数,以便为所有单元格重新评估条件格式。)
|
java.util.List<EvaluationConditionalFormatRule> |
getConditionalFormattingForCell(Cell cell)
This checks all applicable
ConditionalFormattingRule s for the cell's sheet, in defined "priority" order, returning the matches if any.
(这将按照定义的“优先级”顺序检查单元格工作表的所有适用 ConditionalFormattingRules,如果有匹配项,则返回匹配项。)
|
java.util.List<EvaluationConditionalFormatRule> |
getConditionalFormattingForCell(CellReference cellRef)
This checks all applicable
ConditionalFormattingRule s for the cell's sheet, in defined "priority" order, returning the matches if any.
(这将按照定义的“优先级”顺序检查单元格工作表的所有适用 ConditionalFormattingRules,如果有匹配项,则返回匹配项。)
|
java.util.List<EvaluationConditionalFormatRule> |
getFormatRulesForSheet(Sheet sheet)
Retrieve all formatting rules for the given sheet.
(检索给定工作表的所有格式规则。)
|
java.util.List<EvaluationConditionalFormatRule> |
getFormatRulesForSheet(java.lang.String sheetName)
Retrieve all formatting rules for the sheet with the given name.
(检索具有给定名称的工作表的所有格式规则。)
|
java.util.List<Cell> |
getMatchingCells(EvaluationConditionalFormatRule rule)
Retrieve all cells where the given formatting rule evaluates to true.
(检索给定格式规则评估为真的所有单元格。)
|
java.util.List<Cell> |
getMatchingCells(Sheet sheet, int conditionalFormattingIndex, int ruleIndex)
Conditional formatting rules can apply only to cells in the sheet to which they are attached.
(条件格式规则只能应用于它们所附加到的工作表中的单元格。)
|
static CellReference |
getRef(Cell cell) |
protected java.util.List<EvaluationConditionalFormatRule> |
getRules(Sheet sheet)
lazy load by sheet since reading can be expensive
(延迟加载,因为阅读可能很昂贵)
|
protected WorkbookEvaluator |
getWorkbookEvaluator() |
public ConditionalFormattingEvaluator(Workbook wb, WorkbookEvaluatorProvider provider)
protected WorkbookEvaluator getWorkbookEvaluator()
public void clearAllCachedFormats()
public void clearAllCachedValues()
TODO: eventually this should work like EvaluationCache.notifyUpdateCell(int, int, EvaluationCell)
and only clear values that need recalculation based on the formula dependency tree.
protected java.util.List<EvaluationConditionalFormatRule> getRules(Sheet sheet)
sheet
- The sheet to look at
(sheet - 要查看的工作表)
public java.util.List<EvaluationConditionalFormatRule> getConditionalFormattingForCell(CellReference cellRef)
ConditionalFormattingRule
s for the cell's sheet, in defined "priority" order, returning the matches if any. This is a property currently not exposed from
CTCfRule
in
XSSFConditionalFormattingRule
.
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 WorkbookEvaluator.evaluate(String, CellReference, CellRangeAddressBase)
.
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 FormulaEvaluator.evaluateFormulaCell(Cell)
or FormulaEvaluator.evaluateAll()
first, or the wrong conditional results may be returned.
cellRef
- NOTE: if no sheet name is specified, this uses the workbook active sheet
(cellRef - 注意:如果未指定工作表名称,则使用工作簿活动工作表)
EvaluationConditionalFormatRule
s 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 apply
(适用于当前单元格值的评估条件格式规则的不可修改列表,按优先级顺序,由 Excel 评估(XSSF 的最小优先级 #,HSSF 的定义顺序),如果不适用,则为 null)
public java.util.List<EvaluationConditionalFormatRule> getConditionalFormattingForCell(Cell cell)
ConditionalFormattingRule
s for the cell's sheet, in defined "priority" order, returning the matches if any. This is a property currently not exposed from
CTCfRule
in
XSSFConditionalFormattingRule
.
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 WorkbookEvaluator.evaluate(String, CellReference, CellRangeAddressBase)
.
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 FormulaEvaluator.evaluateFormulaCell(Cell)
or FormulaEvaluator.evaluateAll()
first, or the wrong conditional results may be returned.
cell
- The cell to look for
(cell - 要查找的单元格)
EvaluationConditionalFormatRule
s 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 apply
(适用于当前单元格值的评估条件格式规则的不可修改列表,按优先级顺序,由 Excel 评估(XSSF 的最小优先级 #,HSSF 的定义顺序),如果不适用,则为 null)
public static CellReference getRef(Cell cell)
public java.util.List<EvaluationConditionalFormatRule> getFormatRulesForSheet(java.lang.String sheetName)
sheetName
- The name of the sheet to look at
(sheetName - 要查看的工作表的名称)
public java.util.List<EvaluationConditionalFormatRule> getFormatRulesForSheet(Sheet sheet)
sheet
- The sheet to look at
(sheet - 要查看的工作表)
public java.util.List<Cell> getMatchingCells(Sheet sheet, int conditionalFormattingIndex, int ruleIndex)
We could overload this with convenience methods taking a sheet name and sheet index as well.
(条件格式规则只能应用于它们所附加到的工作表中的单元格。 POI 数据模型没有对所属工作表的反向引用,因此必须单独传入。我们可以使用带有工作表名称和工作表索引的便捷方法来重载它。)sheet
- containing the rule
(sheet - 包含规则)
conditionalFormattingIndex
- of the
ConditionalFormatting
instance in the sheet's array
(conditionalFormattingIndex - 工作表数组中的 ConditionalFormatting 实例)
ruleIndex
- of the
ConditionalFormattingRule
instance within the
ConditionalFormatting
(ruleIndex - ConditionalFormatting 中的 ConditionalFormattingRule 实例)
public java.util.List<Cell> getMatchingCells(EvaluationConditionalFormatRule rule)
rule
- The rule to look at
(rule - 要查看的规则)
Copyright 2021 The Apache Software Foundation or its licensors, as applicable.