简体   繁体   English

使用Apache POI替换从属单元格后评估公式

[英]Evaluate formula after replacing dependent cells using Apache POI

I am able to both read and write cell values using Apache POI. 我可以使用Apache POI读取和写入单元格值。 When reading, I evaluate first so that I get the correct values. 阅读时,我首先进行评估,以便获得正确的值。 My use case requires that I read a sheet, replace a few values in the sheet, then read another portion of the sheet that contains cells that depend on the cells I just replaced. 我的用例要求我阅读一张工作表,替换工作表中的一些值,然后再读取工作表的另一部分,其中包含依赖于我刚替换的单元格的单元格。

Example. 例。

A1 contains a formula: =B1+C1 . A1包含一个公式: =B1+C1 B1 contains 2 and C1 contains 3 . B1包含2C1包含3 When I evaluate A1 I correctly get 5 . 当我评估A1我正确得到5 Now, if I replace, with POI api, C1 with 10 , I would expect that when I read A1 again I would see 12 . 现在,如果我用POI api将C1替换为10 ,我希望当我再次阅读A1时会看到12 I don't... A1 now evaluates to null . 我不... A1现在计算为null

Help! 救命!

It seems like your question is answered in Apache POI documentation (under 'Recalculation of Formulas') 看来您的问题在Apache POI文档中得到了解答(在“公式的重新计算”下)

Basically it suggests something like: 基本上,它建议如下:

Workbook wb = ...
wb.getCreationHelper().createFormulaEvaluator().evaluateAll();

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM