Poi公式评估 [英] Poi Formula evaluation

查看:30
本文介绍了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.

在这方面的任何快速帮助都将受到高度赞赏.

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

在添加/编辑完所有单元格之前不要调用它!您也可以只触发一个单元格的评估,请参阅 docs 了解各种选项,如果您需要完全控制.

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天全站免登陆