Bug 46433

Summary: XSSFWorkbook.getCellFormula() Failed
Product: POI Reporter: Matthew <matthew.knl>
Component: XSSFAssignee: POI Developers List <dev>
Severity: normal    
Priority: P2    
Version: 3.5-dev   
Target Milestone: ---   
Hardware: PC   
OS: Windows XP   
Attachments: formula.xlsx

Description Matthew 2008-12-22 02:02:03 UTC
I use following codes to read the formula in attached Excel: formula.xlsx. I found that except the first row, "c.getCellFormula()" return an empty string. In fact, other rows do contain formula.


XSSFWorkbook wb = new XSSFWorkbook("formula.xlsx");

FormulaEvaluator evaluator = wb.getCreationHelper().createFormulaEvaluator();
for(int sheetNum = 0; sheetNum < wb.getNumberOfSheets(); sheetNum++) {
	Sheet sheet = wb.getSheetAt(sheetNum);
	for(Row r : sheet) {
		for(Cell c : r) {
			if(c.getCellType() == Cell.CELL_TYPE_FORMULA) {           			
				System.out.println("c.getCellFormula():" + c.getCellFormula());


Please help. Thanks a lot!
Comment 1 Matthew 2008-12-22 02:02:40 UTC
Created attachment 23046 [details]
Comment 2 Yegor Kozlov 2008-12-22 11:53:40 UTC
Fixed in r728749. 

In some cases Excel attempts to optimize pervasive formulas. Instead of storing similar formula value in each cell, Excel stores a "master" formula and use it as a template. Other cells refer to the master formula by index and convert it to non-shared formula on the fly.  

This support was missing and you got an empty string instead.