If there is a cell with a formula and save the file, then after manually closing the file, the excel will be asked to Save the changes? How to make a full save of file from the program because without this saving, I cannot get the correct value by reading the file.
Current file saving:
File file = new File("Test.xlsx");
FileOutputStream out;
try {
out = new FileOutputStream(file);
workbook.write(out);
workbook.close();
out.flush();
out.close();
} catch (Exception e) {
e.printStackTrace();
}
Formula update:
XSSFFormulaEvaluator.evaluateAllFormulaCells(workbook);
workbook.setForceFormulaRecalculation(true);
Formula:
XSSFCell irrCell = row1.createCell(0);
irrCell.setCellFormula("IFERROR(IRR(A2:C2),0)");
File reading:
try {
workbook = new XSSFWorkbook(file);
System.out.println(workbook.getSheetAt(0).getRow(0).getCell(0).getNumericCellValue());
} catch (InvalidFormatException e) {
e.printStackTrace();
}
Cell values: -20000000, -1000, 2399000
Programm formula cell value: 0, file formula cell value: -0,653687014