![](/img/trans.png)
[英]Error attempting to evaluate cell containing formula of another calculation cell
[英]Evaluate formula and remove formula from cell
我想評估公式並從保持其值的單元格中刪除該公式。 如何使用Apache POI完成此操作?
以下是我評估所有公式的代碼。
FormulaEvaluator evaluator = template.getCreationHelper().createFormulaEvaluator();
int sheetCount = template.getNumberOfSheets();
for(int sheetIndex = 0; sheetIndex < sheetCount; sheetIndex ++) {
sheet = dfaTemplate.getSheetAt(sheetIndex);
for (Row r : sheet) {
for (Cell c : r) {
if (c.getCellType() == Cell.CELL_TYPE_FORMULA) {
evaluator.evaluateFormulaCell(c);
}
}
}
}
您應該使用evaluator.evaluateInCell(cell)
而不是evaluator.evaluateFormulaCell(c)
。 如果單元格包含一個公式,則validateInCell會對該公式求值,並將公式結果放回單元格中,以代替舊公式。
有關更多信息,請參見evaluator.evaluateInCell(cell) 。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.