poi-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From ye...@apache.org
Subject svn commit: r989100 - in /poi/trunk: src/documentation/content/xdocs/ src/java/org/apache/poi/ss/formula/ src/java/org/apache/poi/ss/usermodel/ src/ooxml/testcases/org/apache/poi/xssf/usermodel/ test-data/spreadsheet/
Date Wed, 25 Aug 2010 13:29:56 GMT
Author: yegor
Date: Wed Aug 25 13:29:55 2010
New Revision: 989100

URL: http://svn.apache.org/viewvc?rev=989100&view=rev
Log:
fixed evaluation of XSSF workbooks containing formulas with reference errors (#REF!), see
Bugzilla 49783

Added:
    poi/trunk/test-data/spreadsheet/49783.xlsx   (with props)
Modified:
    poi/trunk/src/documentation/content/xdocs/status.xml
    poi/trunk/src/java/org/apache/poi/ss/formula/FormulaParser.java
    poi/trunk/src/java/org/apache/poi/ss/usermodel/FormulaError.java
    poi/trunk/src/ooxml/testcases/org/apache/poi/xssf/usermodel/TestXSSFBugs.java

Modified: poi/trunk/src/documentation/content/xdocs/status.xml
URL: http://svn.apache.org/viewvc/poi/trunk/src/documentation/content/xdocs/status.xml?rev=989100&r1=989099&r2=989100&view=diff
==============================================================================
--- poi/trunk/src/documentation/content/xdocs/status.xml (original)
+++ poi/trunk/src/documentation/content/xdocs/status.xml Wed Aug 25 13:29:55 2010
@@ -34,6 +34,7 @@
 
     <changes>
         <release version="3.7-beta3" date="2010-??-??">
+           <action dev="POI-DEVELOPERS" type="fix">49783 - fixed evaluation of XSSF
workbooks containing formulas with reference errors (#REF!)</action>
            <action dev="POI-DEVELOPERS" type="fix">49751 - fixed fetching names of
user defined styles in HSSFCellStyle.getUserStyleName()</action>
            <action dev="POI-DEVELOPERS" type="add">48900 - support for protecting a
XSSF workbook</action>
            <action dev="POI-DEVELOPERS" type="fix">49725 - fixed FormulaParser to correctly
process defined names with underscore</action>

Modified: poi/trunk/src/java/org/apache/poi/ss/formula/FormulaParser.java
URL: http://svn.apache.org/viewvc/poi/trunk/src/java/org/apache/poi/ss/formula/FormulaParser.java?rev=989100&r1=989099&r2=989100&view=diff
==============================================================================
--- poi/trunk/src/java/org/apache/poi/ss/formula/FormulaParser.java (original)
+++ poi/trunk/src/java/org/apache/poi/ss/formula/FormulaParser.java Wed Aug 25 13:29:55 2010
@@ -417,8 +417,12 @@ public final class FormulaParser {
 		SimpleRangePart part1 = parseSimpleRangePart();
 		if (part1 == null) {
 			if (sheetIden != null) {
-				throw new FormulaParseException("Cell reference expected after sheet name at index "
-						+ _pointer + ".");
+                if(look == '#'){  // error ref like MySheet!#REF!
+                    return new ParseNode(ErrPtg.valueOf(parseErrorLiteral()));    
+                } else {
+                    throw new FormulaParseException("Cell reference expected after sheet
name at index "
+                            + _pointer + ".");
+                }
 			}
 			return parseNonRange(savePointer);
 		}

Modified: poi/trunk/src/java/org/apache/poi/ss/usermodel/FormulaError.java
URL: http://svn.apache.org/viewvc/poi/trunk/src/java/org/apache/poi/ss/usermodel/FormulaError.java?rev=989100&r1=989099&r2=989100&view=diff
==============================================================================
--- poi/trunk/src/java/org/apache/poi/ss/usermodel/FormulaError.java (original)
+++ poi/trunk/src/java/org/apache/poi/ss/usermodel/FormulaError.java Wed Aug 25 13:29:55 2010
@@ -57,7 +57,7 @@ public enum FormulaError {
      * OFFSET(A1,0,20000) will result in a #REF! error.
      * </p>
      */
-    REF(0x1D, "#REF!"),
+    REF(0x17, "#REF!"),
 
     /**
      * Intended to indicate when what looks like a name is used, but no such name has been
defined.

Modified: poi/trunk/src/ooxml/testcases/org/apache/poi/xssf/usermodel/TestXSSFBugs.java
URL: http://svn.apache.org/viewvc/poi/trunk/src/ooxml/testcases/org/apache/poi/xssf/usermodel/TestXSSFBugs.java?rev=989100&r1=989099&r2=989100&view=diff
==============================================================================
--- poi/trunk/src/ooxml/testcases/org/apache/poi/xssf/usermodel/TestXSSFBugs.java (original)
+++ poi/trunk/src/ooxml/testcases/org/apache/poi/xssf/usermodel/TestXSSFBugs.java Wed Aug
25 13:29:55 2010
@@ -24,15 +24,7 @@ import org.apache.poi.hssf.usermodel.HSS
 import org.apache.poi.openxml4j.opc.OPCPackage;
 import org.apache.poi.openxml4j.opc.PackagePart;
 import org.apache.poi.openxml4j.opc.PackagingURIHelper;
-import org.apache.poi.ss.usermodel.BaseTestBugzillaIssues;
-import org.apache.poi.ss.usermodel.Cell;
-import org.apache.poi.ss.usermodel.DataFormatter;
-import org.apache.poi.ss.usermodel.Font;
-import org.apache.poi.ss.usermodel.FormulaEvaluator;
-import org.apache.poi.ss.usermodel.Name;
-import org.apache.poi.ss.usermodel.Row;
-import org.apache.poi.ss.usermodel.Sheet;
-import org.apache.poi.ss.usermodel.Workbook;
+import org.apache.poi.ss.usermodel.*;
 import org.apache.poi.xssf.XSSFITestDataProvider;
 import org.apache.poi.xssf.XSSFTestDataSamples;
 import org.apache.poi.xssf.usermodel.extensions.XSSFCellFill;
@@ -412,4 +404,29 @@ public final class TestXSSFBugs extends 
         assertEquals("Cycle", wb.getSheetAt(0).getRow(0).getCell(1).getStringCellValue());
 
     }
+
+    public void test49783() throws Exception {
+        Workbook wb =  XSSFTestDataSamples.openSampleWorkbook("49783.xlsx");
+        Sheet sheet = wb.getSheetAt(0);
+        FormulaEvaluator evaluator = wb.getCreationHelper().createFormulaEvaluator();
+        Cell cell;
+
+        cell = sheet.getRow(0).getCell(0);
+        assertEquals("#REF!*#REF!", cell.getCellFormula());
+        assertEquals(Cell.CELL_TYPE_ERROR, evaluator.evaluateInCell(cell).getCellType());
+        assertEquals("#REF!", FormulaError.forInt(cell.getErrorCellValue()).getString());
+
+        Name nm1 = wb.getName("sale_1");
+        assertNotNull("name sale_1 should be present", nm1);
+        assertEquals("Sheet1!#REF!", nm1.getRefersToFormula());
+        Name nm2 = wb.getName("sale_2");
+        assertNotNull("name sale_2 should be present", nm2);
+        assertEquals("Sheet1!#REF!", nm2.getRefersToFormula());
+
+        cell = sheet.getRow(1).getCell(0);
+        assertEquals("sale_1*sale_2", cell.getCellFormula());
+        assertEquals(Cell.CELL_TYPE_ERROR, evaluator.evaluateInCell(cell).getCellType());
+        assertEquals("#REF!", FormulaError.forInt(cell.getErrorCellValue()).getString());
+    }
+
 }

Added: poi/trunk/test-data/spreadsheet/49783.xlsx
URL: http://svn.apache.org/viewvc/poi/trunk/test-data/spreadsheet/49783.xlsx?rev=989100&view=auto
==============================================================================
Binary file - no diff available.

Propchange: poi/trunk/test-data/spreadsheet/49783.xlsx
------------------------------------------------------------------------------
    svn:mime-type = application/octet-stream



---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@poi.apache.org
For additional commands, e-mail: commits-help@poi.apache.org


Mime
View raw message