问题
I am exporting an Excel file with Apache POI using an Excel file as source and for some cells (not all) simply referencing others (like ='worksheet2'.B13
) or calculating a value with referenced cells (like ='worksheet2'.C13 + 'worksheet2'.D13
), they only display zero (0) instead of the right value.
Weird thing is that when I click on the formula and change something in it, as typing a space and deleting it and then I type enter, the right value is displayed !
For info, the type of those cells is "Number / Standard".
I also read somewhere that I should check "Enable iterative calculation" in "Excel options", but it didn't work for me.
Thank you in advance for your help
回答1:
With the help of @JohnBustos and @Gagravarr, I fixed the problem using :
wb.getCreationHelper().createFormulaEvaluator().evaluateAll();
Apparently, Excel caches previously calculated results (in my case it was the Zero in the source Excel file) and we need to trigger recalculation to update them.
See this link : http://poi.apache.org/spreadsheet/eval.html / Section : "Recalculation of Formulas"
来源:https://stackoverflow.com/questions/26592561/excel-cell-displaying-zero-instead-of-a-calculated-referenced-value