Poi Formula evaluation

你离开我真会死。 提交于 2019-12-10 14:02:26

问题


I am facing difficulties while reading formula cell values with POI

I have created formula cell as follows:

cell.setCellType(HSSFCell.CELL_TYPE_FORMULA); 
cell.setCellFormula("SUM(D8..F8)");

And I am reading it as follow:

double formulaCellValue = row.getCell((short) 7).getNumericCellValue();

When read this way(using getNumericCellValue()), I am always getting the value of 0.0.

Any quick help in this regard would be highly appriciated.


回答1:


After you're done setting all your formulas, you need to trigger a recalculation. See the why evaluate docs for the background on why you need to do it, and the Evaluation docs for details. Quick answer is you'd likely want to do something like:

HSSFFormulaEvaluator.evaluateAllFormulaCells(workbook);

Don't call it until you're done adding / editing all your cells though! You can also trigger the evaluation of just one cell, see the docs for details of the various options if you need full control.



来源:https://stackoverflow.com/questions/5747034/poi-formula-evaluation

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