]> source.dussan.org Git - poi.git/commitdiff
Better reporting on why a test is failing, and partial NameXPxg eval
authorNick Burch <nick@apache.org>
Sat, 19 Jul 2014 21:27:28 +0000 (21:27 +0000)
committerNick Burch <nick@apache.org>
Sat, 19 Jul 2014 21:27:28 +0000 (21:27 +0000)
git-svn-id: https://svn.apache.org/repos/asf/poi/trunk@1611969 13f79535-47bb-0310-9956-ffa450edef68

src/java/org/apache/poi/ss/formula/WorkbookEvaluator.java
src/java/org/apache/poi/ss/formula/eval/NameXEval.java
src/ooxml/testcases/org/apache/poi/xssf/usermodel/TestXSSFBugs.java

index ec3f984315500af30a17cec69fc1fd9c84e359da..6dd5dd20687d8923ec011213ee321061bdb1090e 100644 (file)
@@ -62,6 +62,7 @@ import org.apache.poi.ss.formula.ptg.MemFuncPtg;
 import org.apache.poi.ss.formula.ptg.MissingArgPtg;
 import org.apache.poi.ss.formula.ptg.NamePtg;
 import org.apache.poi.ss.formula.ptg.NameXPtg;
+import org.apache.poi.ss.formula.ptg.NameXPxg;
 import org.apache.poi.ss.formula.ptg.NumberPtg;
 import org.apache.poi.ss.formula.ptg.OperationPtg;
 import org.apache.poi.ss.formula.ptg.Ptg;
@@ -650,6 +651,25 @@ public final class WorkbookEvaluator {
                return eval;
            }
        }
+       if (ptg instanceof NameXPxg) {
+           // TODO This is a temporary hack....
+           NameXPxg pxg = (NameXPxg)ptg;
+           int sIdx = -1;
+           if (pxg.getSheetName() != null) {
+               sIdx = _workbook.getSheetIndex(pxg.getSheetName());
+           }
+           EvaluationName evalName = _workbook.getName(pxg.getNameName(), sIdx);
+           if (evalName == null) {
+               // We don't know about that name, sorry
+               // TODO What about UDFs?
+               logInfo("Unknown Name referenced: " + pxg.getNameName());
+               return ErrorEval.NAME_INVALID;
+           }
+           
+           int nIdx = evalName.createPtg().getIndex();
+           NameXPtg nptg = new NameXPtg(sIdx, nIdx);
+           return getEvalForPtg(nptg, ec);
+       }
 
        if (ptg instanceof IntPtg) {
            return new NumberEval(((IntPtg)ptg).getValue());
index 32831bc25812421cea4cbd8225d0570899366069..e7e9bf881a33139c4f187bc01ac1faac79519870 100644 (file)
@@ -20,10 +20,9 @@ package org.apache.poi.ss.formula.eval;
 import org.apache.poi.ss.formula.ptg.NameXPtg;
 
 /**
- * @author Josh Micich
+ * Evaluation of a Name defined in a Sheet or Workbook scope
  */
 public final class NameXEval implements ValueEval {
-
        private final NameXPtg _ptg;
 
        public NameXEval(NameXPtg ptg) {
index 92090c0e7a1fe389da0857109a74b74486387514..b1f223e1c3169fd45b5f35a9cbe907b061e01818 100644 (file)
@@ -266,6 +266,7 @@ public final class TestXSSFBugs extends BaseTestBugzillaIssues {
     public void bug48539() throws Exception {
        XSSFWorkbook wb = XSSFTestDataSamples.openSampleWorkbook("48539.xlsx");
        assertEquals(3, wb.getNumberOfSheets());
+       assertEquals(0, wb.getNumberOfNames());
        
        // Try each cell individually
        XSSFFormulaEvaluator eval = new XSSFFormulaEvaluator(wb);
@@ -274,7 +275,14 @@ public final class TestXSSFBugs extends BaseTestBugzillaIssues {
           for(Row r : s) {
              for(Cell c : r) {
                 if(c.getCellType() == Cell.CELL_TYPE_FORMULA) {
-                    CellValue cv = eval.evaluate(c);
+                    String formula = c.getCellFormula();
+                    CellValue cv;
+                    try {
+                        cv = eval.evaluate(c);
+                    } catch (Exception e) {
+                        throw new RuntimeException("Can't evaluate formula: " + formula, e);
+                    }
+                    
                     if(cv.getCellType() == Cell.CELL_TYPE_NUMERIC) {
                         // assert that the calculated value agrees with
                         // the cached formula result calculated by Excel
@@ -1661,7 +1669,7 @@ public final class TestXSSFBugs extends BaseTestBugzillaIssues {
      * org.apache.poi.ss.formula.FormulaParseException: Parse error near char 0 '[' in specified formula '[0]!NR_Global_B2'. Expected number, string, or defined name 
      */
     @Test
-    @Ignore
+    @Ignore("Bug 56737 remains outstanding to fix")
     public void bug56737() throws IOException {
         Workbook wb = XSSFTestDataSamples.openSampleWorkbook("56737.xlsx");