我試圖使用POI XSSF來評估一些Excel公式。 這些值不必保存,我可能必須計算許多公式,所以我試圖在同一個單元格中完成所有操作。使用Apache POI在電子表格中重新計算公式使用
的問題是,單元格的值似乎停滯在第一個公式中輸入即使我重新計算
FormulaEvaluator evaluator = wb.getCreationHelper().createFormulaEvaluator();
XSSFCell formulaCell = row.createCell(6);
formulaCell.setCellFormula("Date(2011,10,6)");
CellValue cellValue = evaluator.evaluate(formulaCell);
System.out.println(cellValue.getNumberValue());
formulaCell.setCellFormula("Date(1911,3,4)");
cellValue = evaluator.evaluate(formulaCell);
System.out.println(cellValue.getNumberValue());
此輸出40822.0 40822.0(EXCEL的2011年10月6日當量)兩次,而不是重新評估新的公式。