]> source.dussan.org Git - poi.git/commitdiff
Further XSSF external name evaluation lookup support
authorNick Burch <nick@apache.org>
Wed, 23 Jul 2014 19:09:25 +0000 (19:09 +0000)
committerNick Burch <nick@apache.org>
Wed, 23 Jul 2014 19:09:25 +0000 (19:09 +0000)
git-svn-id: https://svn.apache.org/repos/asf/poi/trunk@1612925 13f79535-47bb-0310-9956-ffa450edef68

src/ooxml/java/org/apache/poi/xssf/usermodel/XSSFEvaluationWorkbook.java

index d9d53f7ce4ae2fdcc795ed36ccca74f15fa8aba9..d9486e3bc2759d21c19494a665c3586ea6bd85bd 100644 (file)
@@ -110,7 +110,9 @@ public final class XSSFEvaluationWorkbook implements FormulaRenderingWorkbook, E
                for (int i = 0; i < _uBook.getNumberOfNames(); i++) {
                        XSSFName nm = _uBook.getNameAt(i);
                        String nameText = nm.getNameName();
-                       if (name.equalsIgnoreCase(nameText) && nm.getSheetIndex() == sheetIndex) {
+                       int nameSheetindex = nm.getSheetIndex();
+                       if (name.equalsIgnoreCase(nameText) && 
+                              (nameSheetindex == -1 || nameSheetindex == sheetIndex)) {
                                return new Name(_uBook.getNameAt(i), i, this);
                        }
                }
@@ -138,10 +140,14 @@ public final class XSSFEvaluationWorkbook implements FormulaRenderingWorkbook, E
             
             for (org.apache.poi.ss.usermodel.Name name : linkTable.getDefinedNames()) {
                 if (name.getNameName().equals(nameName)) {
+                    // HSSF returns one sheet higher than normal, and various bits
+                    //  of the code assume that. So, make us match that behaviour!
+                    int nameSheetIndex = name.getSheetIndex() + 1;
+                    
                     // TODO Return a more specialised form of this, see bug #56752
                     // Should include the cached values, for in case that book isn't available
                     // Should support XSSF stuff lookups
-                    return new ExternalName(nameName, -1, name.getSheetIndex());
+                    return new ExternalName(nameName, -1, nameSheetIndex);
                 }
             }
             throw new IllegalArgumentException("Name '"+nameName+"' not found in " +