I use Apache POI for creating a Excel File. There are two diffrent sheets. Sheet 1 is a template with some formulars. In Sheet 2 i want to get the the value of one cell in Sheet 1. This is the Excel-formula to get the value from Sheet 1:
=IF(Sheet1!D7="";"";Sheet1!D7)
But when I put some text in D7 with
cell = worksheet1.getRow(6).getCell(3);
cell.setCellValue("SomeText");
it wont take over the value to Sheet 2. If i click into D7 and use enter, Sheet2 will take the value, but i want, that apache poi do this.
How can I handle this?
You have to evaluate the formula before final output.
Use this in order to evaluate all formulas.
FormulaEvaluator formulaEvaluator = workbook.getCreationHelper().createFormulaEvaluator();
formulaEvaluator.evaluateAll();
Use this in order to evaluate the formula of a specific cell
FormulaEvaluator evaluator = wb.getCreationHelper().createFormulaEvaluator();
evaluator.evaluateFormulaCell(cell);
And then write the file in the stream
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.