繁体   English   中英

评估公式并从单元格中删除公式

[英]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.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM