Bug 49872

Summary: XSSFFormulaEvaluator.evaluateInCell() with "shared" formula's
Product: POI Reporter: alex <i8c.alex>
Component: XSSFAssignee: POI Developers List <dev>
Status: RESOLVED FIXED    
Severity: normal    
Priority: P2    
Version: 3.6-dev   
Target Milestone: ---   
Hardware: PC   
OS: Windows XP   
Attachments: Example file and code

Description alex 2010-09-03 02:25:10 UTC
If you have a shared formula, and you run evaluateInCell() on the original formula, the referenced formula's will fail because the original formula can no longer be found, XSSFCell throws a nullpointer exception on "convertSharedFormula()" because "sfCell.getCTCell().getF()" is null.

I'm not entirely sure if this is a bug or a feature.
Comment 1 Yegor Kozlov 2010-09-04 11:27:48 UTC
I'm not quite sure how to reproduce it. Can you attach a sample file and Java code that demonstrates the problem? 


Yegor
Comment 2 alex 2010-09-06 03:03:50 UTC
Created attachment 25990 [details]
Example file and code
Comment 3 Yegor Kozlov 2010-09-12 05:15:31 UTC
It was a bug. The same workbook saved as .xls evaluates OK in HSSF.  

When a group of cells shares a formula then only the first cell in the group contains the actual formula expression. This is considered the 'master' formula cell. Subsequent cells refer to the master by id and adjust the expression based on the cell's relative location to the master formula.

FormulaEvaluator.evaluateInCell changes cell type. This method evaluates the formula, and puts the result back into the cell, in place of the old formula. 
In your case, the first call of evaluateInCell changed the master shared formula and subsequent calls on dependent cells resulted in NPE. 

I committed the fix in r996265. Now you can call evaluateInCell on a group of shared formulas cells in any order - first master then dependent or first dependent cells and then master. 

Yegor