andyczerwonka
andyczerwonka

Reputation: 4260

Evaluate formula after replacing dependent cells using Apache POI

I am able to both read and write cell values using 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. B1 contains 2 and C1 contains 3. When I evaluate A1 I correctly get 5. Now, if I replace, with POI api, C1 with 10, I would expect that when I read A1 again I would see 12. I don't... A1 now evaluates to null.

Help!

Upvotes: 2

Views: 1559

Answers (1)

Grzegorz Oledzki
Grzegorz Oledzki

Reputation: 24261

It seems like your question is answered in Apache POI documentation (under 'Recalculation of Formulas')

Basically it suggests something like:

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

Upvotes: 1

Related Questions