https://issues.apache.org/bugzilla/show_bug.cgi?id=51875

             Bug #: 51875
           Summary: Newline characters in shared formulas for XLSX sheets
                    results in FormulaParseException
           Product: POI
           Version: 3.8-dev
          Platform: PC
            Status: NEW
          Severity: normal
          Priority: P2
         Component: XSSF
        AssignedTo: [email protected]
        ReportedBy: [email protected]
    Classification: Unclassified


Created attachment 27570
  --> https://issues.apache.org/bugzilla/attachment.cgi?id=27570
Updated test-data/spreadsheet/NewlineInFormulas.xlsx containing shared formula
with newline to trigger exception

When a shared formular in a XLSM sheet contains a newline ('\r\n') character
POI throws an exception:

org.apache.poi.ss.formula.FormulaParseException: Unused input [
+B2] after attempting to parse the formula [B1
+B2]
    at org.apache.poi.ss.formula.FormulaParser.parse(FormulaParser.java:1571)
    at org.apache.poi.ss.formula.FormulaParser.parse(FormulaParser.java:174)
    at
org.apache.poi.xssf.usermodel.XSSFCell.convertSharedFormula(XSSFCell.java:396)
    at org.apache.poi.xssf.usermodel.XSSFCell.getCellFormula(XSSFCell.java:368)
    at
org.apache.poi.xssf.usermodel.XSSFEvaluationWorkbook.getFormulaTokens(XSSFEvaluationWorkbook.java:150)
    at
org.apache.poi.ss.formula.WorkbookEvaluator.evaluateAny(WorkbookEvaluator.java:281)
    at
org.apache.poi.ss.formula.WorkbookEvaluator.evaluate(WorkbookEvaluator.java:225)
    at
org.apache.poi.xssf.usermodel.XSSFFormulaEvaluator.evaluateFormulaCellValue(XSSFFormulaEvaluator.java:264)
    at
org.apache.poi.xssf.usermodel.XSSFFormulaEvaluator.evaluateFormulaCell(XSSFFormulaEvaluator.java:151)
    at
org.apache.poi.xssf.usermodel.TestXSSFBugs.test50440(TestXSSFBugs.java:637)
   ...

My proposed fix modifies the formula parser to treat newlines like whitespaces
(which get skipped and therefore will prevent the parser to 'throw up' when
encountering newlines).

This makes a previous workaround obsolete (see
https://issues.apache.org/bugzilla/show_bug.cgi?id=50440).

Patch will follow.

Cheers,
Marcel

-- 
Configure bugmail: https://issues.apache.org/bugzilla/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
You are the assignee for the bug.

---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to