Bug 46433 - XSSFWorkbook.getCellFormula() Failed
Summary: XSSFWorkbook.getCellFormula() Failed
Alias: None
Product: POI
Classification: Unclassified
Component: XSSF (show other bugs)
Version: 3.5-dev
Hardware: PC Windows XP
: P2 normal (vote)
Target Milestone: ---
Assignee: POI Developers List
Depends on:
Reported: 2008-12-22 02:02 UTC by Matthew
Modified: 2008-12-22 11:53 UTC (History)
0 users

formula.xlsx (7.41 KB, application/zip)
2008-12-22 02:02 UTC, Matthew

Note You need to log in before you can comment on or make changes to this bug.
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.