Bug 51533 - XSSFWorksheet setSheetName throws FormulaParseException on shared formula.
Summary: XSSFWorksheet setSheetName throws FormulaParseException on shared formula.
Alias: None
Product: POI
Classification: Unclassified
Component: XSSF (show other bugs)
Version: 3.8-dev
Hardware: PC Windows XP
: P2 minor (vote)
Target Milestone: ---
Assignee: POI Developers List
Depends on:
Reported: 2011-07-20 01:23 UTC by Chris Brawn
Modified: 2011-07-20 09:43 UTC (History)
0 users


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

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.