Bug 51533

Summary: XSSFWorksheet setSheetName throws FormulaParseException on shared formula.
Product: POI Reporter: Chris Brawn <chris>
Component: XSSFAssignee: POI Developers List <dev>
Status: RESOLVED FIXED    
Severity: minor    
Priority: P2    
Version: 3.8-dev   
Target Milestone: ---   
Hardware: PC   
OS: Windows XP   

Description Chris Brawn 2011-07-20 01:23:59 UTC
Changing sheet name on an Excel 2010 worksheet using XSSFWorksheet generates the following error during the XSSFormulaUtils.updateSheetName() method.

Note:  'C' in first line was an unprintable character.

Parse error near char 0 'C' in specified formula ''. Expected cell ref or constant literal
	at org.apache.poi.ss.formula.FormulaParser.expected(FormulaParser.java:217)
	at org.apache.poi.ss.formula.FormulaParser.parseSimpleFactor(FormulaParser.java:1122)
	at org.apache.poi.ss.formula.FormulaParser.percentFactor(FormulaParser.java:1077)
	at org.apache.poi.ss.formula.FormulaParser.powerFactor(FormulaParser.java:1064)
	at org.apache.poi.ss.formula.FormulaParser.Term(FormulaParser.java:1424)
	at org.apache.poi.ss.formula.FormulaParser.additiveExpression(FormulaParser.java:1524)
	at org.apache.poi.ss.formula.FormulaParser.concatExpression(FormulaParser.java:1508)
	at org.apache.poi.ss.formula.FormulaParser.comparisonExpression(FormulaParser.java:1465)
	at org.apache.poi.ss.formula.FormulaParser.unionExpression(FormulaParser.java:1445)
	at org.apache.poi.ss.formula.FormulaParser.parse(FormulaParser.java:1566)
	at org.apache.poi.ss.formula.FormulaParser.parse(FormulaParser.java:174)
	at org.apache.poi.xssf.usermodel.helpers.XSSFFormulaUtils.updateFormula(XSSFFormulaUtils.java:125)
	at org.apache.poi.xssf.usermodel.helpers.XSSFFormulaUtils.updateSheetName(XSSFFormulaUtils.java:106)
	at org.apache.poi.xssf.usermodel.XSSFWorkbook.setSheetName(XSSFWorkbook.java:1130)


The XSSFFormulaUtils.updateFormula() method retrieves the string value of the cell's F-node (function), which returns a valid but empty string ('').  The NULL-check prior to attempting to parse the formula doesn't handle the empty string.  These empty F-node strings are generated on a shared formula cell.

An example of this cell is:

<c r="E6" s="22">
  <f t="shared" si="0" /> 
  <v>8</v> 
  </c>

Other formula read and resolution methods correctly handle shared formula definitions.
Comment 1 Yegor Kozlov 2011-07-20 09:43:14 UTC
Fixed in r1148673, junit added. 

Regards,
Yegor