]> source.dussan.org Git - poi.git/commitdiff
fixed evaluation of XSSF workbooks containing formulas with reference errors (#REF...
authorYegor Kozlov <yegor@apache.org>
Wed, 25 Aug 2010 13:29:55 +0000 (13:29 +0000)
committerYegor Kozlov <yegor@apache.org>
Wed, 25 Aug 2010 13:29:55 +0000 (13:29 +0000)
git-svn-id: https://svn.apache.org/repos/asf/poi/trunk@989100 13f79535-47bb-0310-9956-ffa450edef68

src/documentation/content/xdocs/status.xml
src/java/org/apache/poi/ss/formula/FormulaParser.java
src/java/org/apache/poi/ss/usermodel/FormulaError.java
src/ooxml/testcases/org/apache/poi/xssf/usermodel/TestXSSFBugs.java
test-data/spreadsheet/49783.xlsx [new file with mode: 0644]

index 67f61e161533f4c9380e99f7b60f3892d7d03655..7668ebc6f67111ccb9f9c35794830516aaad307b 100644 (file)
@@ -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>
index 0f186e7449a43141481eea7028304663e6a88eea..db46b53e868f86a951dd32747f9573d3742453bb 100644 (file)
@@ -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);
                }
index c3c43301e51d94d78d168ab2230bd620c1f7e304..162f24aa4bd1d62e4fe8e354dd933cf622cce056 100644 (file)
@@ -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.
index 5a6e250d9eb4398650a2205d46849e14cb1a61e3..e9daa37bfdf2f8823f1e2aec53c0ea9b79926f19 100644 (file)
@@ -24,15 +24,7 @@ import org.apache.poi.hssf.usermodel.HSSFWorkbook;
 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 BaseTestBugzillaIssues {
         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());
+    }
+
 }
diff --git a/test-data/spreadsheet/49783.xlsx b/test-data/spreadsheet/49783.xlsx
new file mode 100644 (file)
index 0000000..09cda15
Binary files /dev/null and b/test-data/spreadsheet/49783.xlsx differ