POI公式求值 [英] Poi Formula evaluation

查看:253
本文介绍了POI公式求值的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我现在面临的困难,同时读取与POI公式单元格值

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)");

和我读它如下:

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

在阅读这种方式(使用 getNumericCellValue()),我总是得到0.0的值。

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

在这方面的任何快速帮助将是非常appriciated。

Any quick help in this regard would be highly appriciated.

推荐答案

你完成设置你所有的公式后,你需要触发重新计算。请参阅为什么评估文档为背景的,为什么你需要做到这一点,而评估文档了解详情。快速的答案是可能你想要做的是这样的:

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.

这篇关于POI公式求值的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆