Excel单元格显示零而不是计算/参考值 [英] Excel cell displaying zero instead of a calculated / referenced value
问题描述
我正在使用Excel文件作为源导出Apache POI的Excel文件,并且对于某些单元格(并非全部)仅引用其他单元格(例如='worksheet2'.B13
)或使用引用的单元格(例如='worksheet2'.C13 + 'worksheet2'.D13
)计算值,它们仅显示零(0)而不是正确的值.
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.
奇怪的是,当我单击公式并对其进行更改时,如键入空格并删除它,然后键入Enter,则会显示正确的值!
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".
我还读过某个地方,我应该在"Excel选项"中选中启用迭代计算",但这对我不起作用.
I also read somewhere that I should check "Enable iterative calculation" in "Excel options", but it didn't work for me.
预先感谢您的帮助
推荐答案
借助@JohnBustos和@Gagravarr,我使用以下方法解决了该问题:
wb.getCreationHelper().createFormulaEvaluator().evaluateAll();
With the help of @JohnBustos and @Gagravarr, I fixed the problem using :
wb.getCreationHelper().createFormulaEvaluator().evaluateAll();
显然,Excel会缓存先前计算的结果(在我的情况下,它是源Excel文件中的零),我们需要触发重新计算来更新它们.
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.
查看此链接: http://poi.apache.org/spreadsheet/eval.html /部分:公式的重新计算"
See this link : http://poi.apache.org/spreadsheet/eval.html / Section : "Recalculation of Formulas"
这篇关于Excel单元格显示零而不是计算/参考值的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!