public interface FormulaEvaluator
For performance reasons, this class keeps a cache of all previously calculated intermediate cell values. Be sure to call clearAllCachedResultValues()
if any workbook cells are changed between calls to evaluate~ methods on this class.
Modifier and Type | Method and Description |
---|---|
void |
clearAllCachedResultValues()
Should be called whenever there are changes to input cells in the evaluated workbook.
(每当评估工作簿中的输入单元格发生更改时,都应该调用它。)
|
CellValue |
evaluate(Cell cell)
If cell contains a formula, the formula is evaluated and returned, else the CellValue simply copies the appropriate cell value from the cell and also its cell type.
(如果单元格包含公式,则计算并返回公式,否则 CellValue 只是从单元格中复制适当的单元格值及其单元格类型。)
|
void |
evaluateAll()
Loops over all cells in all sheets of the associated workbook.
(循环遍历关联工作簿的所有工作表中的所有单元格。)
|
CellType |
evaluateFormulaCell(Cell cell)
If cell contains formula, it evaluates the formula, and saves the result of the formula.
(如果单元格包含公式,它会计算公式,并保存公式的结果。)
|
Cell |
evaluateInCell(Cell cell)
If cell contains formula, it evaluates the formula, and puts the formula result back into the cell, in place of the old formula.
(如果单元格包含公式,它会计算公式,并将公式结果放回单元格中,以代替旧公式。)
|
void |
notifyDeleteCell(Cell cell)
Should be called to tell the cell value cache that the specified cell has just become a formula cell, or the formula text has changed
(应该调用来告诉单元格值缓存指定单元格刚刚变成公式单元格,或者公式文本已经改变)
|
void |
notifySetFormula(Cell cell)
Should be called to tell the cell value cache that the specified (value or formula) cell has changed.
(应该调用以告诉单元格值缓存指定的(值或公式)单元格已更改。)
|
void |
notifyUpdateCell(Cell cell)
Should be called to tell the cell value cache that the specified (value or formula) cell has changed.
(应该调用以告诉单元格值缓存指定的(值或公式)单元格已更改。)
|
void |
setDebugEvaluationOutputForNextEval(boolean value)
Perform detailed output of formula evaluation for next evaluation only? Is for developer use only (also developers using POI for their XLS files).
(只为下次评估执行公式评估的详细输出?仅供开发人员使用(开发人员也将 POI 用于他们的 XLS 文件)。)
|
void |
setIgnoreMissingWorkbooks(boolean ignore)
Whether to ignore missing references to external workbooks and use cached formula results in the main workbook instead.
(是否忽略对外部工作簿的缺失引用并在主工作簿中使用缓存的公式结果。)
|
void |
setupReferencedWorkbooks(java.util.Map<java.lang.String,FormulaEvaluator> workbooks)
Sets up the Formula Evaluator to be able to reference and resolve links to other workbooks, eg [Test.xls]Sheet1!A1.
(设置公式评估器以能够引用和解析指向其他工作簿的链接,例如 [Test.xls]Sheet1!A1。)
|
void clearAllCachedResultValues()
void notifySetFormula(Cell cell)
void notifyDeleteCell(Cell cell)
void notifyUpdateCell(Cell cell)
void evaluateAll()
CellValue evaluate(Cell cell)
cell
- The
Cell
to evaluate
(cell - 要评估的单元格)
CellType evaluateFormulaCell(Cell cell)
int evaluatedCellType = evaluator.evaluateFormulaCell(cell);Be aware that your cell will hold both the formula, and the result. If you want the cell replaced with the result of the formula, use
evaluateInCell(Cell)
(如果单元格包含公式,它会计算公式,并保存公式的结果。该单元格保留为公式单元格。否则,如果单元格不包含公式,则此方法使单元格保持不变。请注意,返回的是公式结果的类型,因此您知道公式中还存储了什么样的值。 int evaluateCellType = evaluator.evaluateFormulaCell(cell);请注意,您的单元格将包含公式和结果。如果要将单元格替换为公式的结果,请使用 evaluateInCell(Cell))
cell
- The cell to evaluate
(cell - 要评估的单元格)
CellType.NUMERIC
,
CellType.STRING
,
CellType.BOOLEAN
,
CellType.ERROR
Note: the cell's type remains as CellType.FORMULA however.
(公式结果的类型,即如果单元格不是公式,则为 -1,或者 CellType.NUMERIC、CellType.STRING、CellType.BOOLEAN、CellType.ERROR 之一 注意:单元格的类型仍然为 CellType.FORMULA。)
Cell evaluateInCell(Cell cell)
int evaluatedCellType = evaluator.evaluateInCell(cell).getCellType();Be aware that your cell value will be changed to hold the result of the formula. If you simply want the formula value computed for you, use
evaluateFormulaCell(Cell)
(如果单元格包含公式,它会计算公式,并将公式结果放回单元格中,以代替旧公式。否则,如果单元格不包含公式,则此方法使单元格保持不变。请注意,返回相同的 Cell 实例以允许链式调用,例如: int evaluateCellType = evaluator.evaluateInCell(cell).getCellType();请注意,您的单元格值将更改为保存公式的结果。如果您只想为您计算公式值,请使用 evaluateFormulaCell(Cell))
cell
- The
Cell
to evaluate and modify.
(cell - 要评估和修改的 Cell。)
void setupReferencedWorkbooks(java.util.Map<java.lang.String,FormulaEvaluator> workbooks)
For a workbook referenced as [Test.xls]Sheet1!A1, you should supply a map containing the key Test.xls (no square brackets), and an open FormulaEvaluator onto that Workbook.
(设置公式评估器以能够引用和解析指向其他工作簿的链接,例如 [Test.xls]Sheet1!A1。对于引用为 [Test.xls]Sheet1!A1 的工作簿,您应该提供一个包含键 Test.xls(无方括号)的映射,并在该工作簿上提供一个打开的 FormulaEvaluator。)workbooks
- Map of workbook names (no square brackets) to an evaluator on that workbook
(工作簿 - 工作簿名称(无方括号)映射到该工作簿上的评估者)
void setIgnoreMissingWorkbooks(boolean ignore)
In some cases external workbooks referenced by formulas in the main workbook are not available. With this method you can control how POI handles such missing references:
CollaboratingWorkbooksEnvironment.WorkbookNotFoundException
if an external reference cannot be resolvedignore
- whether to ignore missing references to external workbooks
(ignore - 是否忽略对外部工作簿的缺失引用)
void setDebugEvaluationOutputForNextEval(boolean value)
value
- whether to perform detailed output
(value - 是否进行详细输出)
Copyright 2021 The Apache Software Foundation or its licensors, as applicable.