Excel cell displaying zero instead of a calculated / referenced value

你。 提交于 2019-12-11 13:33:02

问题


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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!