]> source.dussan.org Git - poi.git/commitdiff
Bit more towards XSSF name support for #56737, will need some deeper changes though...
authorNick Burch <nick@apache.org>
Fri, 18 Jul 2014 22:50:54 +0000 (22:50 +0000)
committerNick Burch <nick@apache.org>
Fri, 18 Jul 2014 22:50:54 +0000 (22:50 +0000)
git-svn-id: https://svn.apache.org/repos/asf/poi/trunk@1611830 13f79535-47bb-0310-9956-ffa450edef68

src/ooxml/java/org/apache/poi/xssf/usermodel/XSSFEvaluationWorkbook.java
src/testcases/org/apache/poi/hssf/usermodel/TestBugs.java
test-data/spreadsheet/ref-56737.xlsx [new file with mode: 0644]

index 660f2dc40c4ff20ade4c8249611ab32ba4f8f31d..ea9f93d619aecbc05c9d5e73567edb648242660b 100644 (file)
@@ -103,16 +103,39 @@ public final class XSSFEvaluationWorkbook implements FormulaRenderingWorkbook, E
        }
 
        public NameXPtg getNameXPtg(String name, int sheetRefIndex) {
+           // First, try to find it as a User Defined Function
         IndexedUDFFinder udfFinder = (IndexedUDFFinder)getUDFFinder();
         FreeRefFunction func = udfFinder.findFunction(name);
-               if(func == null) return null;
-        else return new NameXPtg(0, udfFinder.getFunctionIndex(name));
+        if (func != null) {
+            return new NameXPtg(0, udfFinder.getFunctionIndex(name));
+        }
+        
+        // Otherwise, try it as a named range
+        XSSFName xname = _uBook.getName(name);
+        if (xname != null) {
+            int nameAt = _uBook.getNameIndex(name);
+            return new NameXPtg(xname.getSheetIndex(), nameAt);
+        } else {
+            return null;
+        }
        }
 
     public String resolveNameXText(NameXPtg n) {
         int idx = n.getNameIndex();
+        String name = null;
+        
+        // First, try to find it as a User Defined Function
         IndexedUDFFinder udfFinder = (IndexedUDFFinder)getUDFFinder();
-        return udfFinder.getFunctionName(idx);
+        name = udfFinder.getFunctionName(idx);
+        if (name != null) return name;
+        
+        // Otherwise, try it as a named range
+        XSSFName xname = _uBook.getNameAt(idx);
+        if (xname != null) {
+            name = xname.getNameName();
+        }
+        
+        return name;
     }
 
        public EvaluationSheet getSheet(int sheetIndex) {
index ad6f693ab2e8381b338a20205bf2670d75f4d509..9421b5634800f98b8b09acb5711614142d3188bc 100644 (file)
@@ -2678,10 +2678,5 @@ public final class TestBugs extends BaseTestBugzillaIssues {
         
         // Try to evaluate everything
         eval.evaluateAll();
-        
-        // Try to set the same kinds of formula elsewhere
-        Cell newF = s.getRow(0).createCell(10, Cell.CELL_TYPE_FORMULA);
-        // TODO Fix this
-        //newF.setCellFormula("Defines!NR_To_A1");
     }
 }
diff --git a/test-data/spreadsheet/ref-56737.xlsx b/test-data/spreadsheet/ref-56737.xlsx
new file mode 100644 (file)
index 0000000..3703827
Binary files /dev/null and b/test-data/spreadsheet/ref-56737.xlsx differ