I'm using Apache POI to save data to an excel file. Basic data is being saved fine, but I need to also use formula's.
Its adding the formula in, but its not being evaluated until I refresh the cell (clicking into and pressing enter)
The code I'm using to create the cells. Removed code that's not relevant
public void writeExcel(ClassManager cm) throws FileNotFoundException, IOException {
setupRows();
workbook.setForceFormulaRecalculation(true);
FileOutputStream outputStream = new FileOutputStream(fileLocation);
workbook.write(outputStream);
workbook.close();
}
public void setupRows() {
setupRow15();
}
public void setupRow15() {
int start = 2;
Row row = sheet.createRow(16);
// Create 1st Cell
Cell cell = row.createCell(0);
cell.setCellValue("templateId = ");
for (int i = 0; i < classes.size(); i++) {
// Get class
Classes c = classes.get(i);
// Create cell
cell = row.createCell(start);
// Set contents
cell.setCellFormula("IF(C3=\"\",\"\",CONCAT($A17,$B17,C" + (start + 1) + ",$B17,$A$16))");
start++;
}
}
It's resulting in the formula