]> source.dussan.org Git - poi.git/commitdiff
Fix bug #45430 - Correct named range sheet reporting when no local sheet id is given...
authorNick Burch <nick@apache.org>
Fri, 18 Jul 2008 17:37:44 +0000 (17:37 +0000)
committerNick Burch <nick@apache.org>
Fri, 18 Jul 2008 17:37:44 +0000 (17:37 +0000)
git-svn-id: https://svn.apache.org/repos/asf/poi/branches/ooxml@677979 13f79535-47bb-0310-9956-ffa450edef68

src/documentation/content/xdocs/changes.xml
src/documentation/content/xdocs/status.xml
src/ooxml/java/org/apache/poi/xssf/usermodel/XSSFName.java
src/ooxml/testcases/org/apache/poi/xssf/usermodel/AllXSSFUsermodelTests.java
src/ooxml/testcases/org/apache/poi/xssf/usermodel/TestXSSFBugs.java [new file with mode: 0644]
src/testcases/org/apache/poi/hssf/data/45430.xlsx [new file with mode: 0644]

index 99106b3a0aed51cc2085e3dbf85e0748e1fd2d37..bbfad9132ee52b4288520604fcb86a098e0577f5 100644 (file)
     </devs>
 
                <!-- Don't forget to update status.xml too! -->
-<!--
         <release version="3.5.1-beta2" date="2008-??-??">
+           <action dev="POI-DEVELOPERS" type="fix">45430 - Correct named range sheet reporting when no local sheet id is given in the xml</action>
                </release>
--->
         <release version="3.5.1-beta1" date="2008-07-18">
            <action dev="POI-DEVELOPERS" type="add">45018 - Support for fetching embeded documents from within an OOXML file</action>
            <action dev="POI-DEVELOPERS" type="add">Port support for setting a policy on missing / blank cells when fetching, to XSSF too</action>
index 96ff195f29c47367cb5ba73ec2abc67692931f92..0c4d945e40daea557d091da666d8082cd0c5bbbf 100644 (file)
 
        <!-- Don't forget to update changes.xml too! -->
     <changes>
-<!--
         <release version="3.5.1-beta2" date="2008-??-??">
+           <action dev="POI-DEVELOPERS" type="fix">45430 - Correct named range sheet reporting when no local sheet id is given in the xml</action>
                </release>
--->
         <release version="3.5.1-beta1" date="2008-07-18">
            <action dev="POI-DEVELOPERS" type="add">45018 - Support for fetching embeded documents from within an OOXML file</action>
            <action dev="POI-DEVELOPERS" type="add">Port support for setting a policy on missing / blank cells when fetching, to XSSF too</action>
index 5392bfce8d49e7e51c55bdbaab067eebfa653e99..fd5f544b18505526a2bb6afc19f14782e0a12959 100644 (file)
@@ -57,10 +57,21 @@ public class XSSFName implements Name {
        }
        
        public String getSheetName() {
-               long sheetId = ctName.getLocalSheetId();
-               if(sheetId >= 0) {
-                       return workbook.getSheetName((int)sheetId);
+               if(ctName.isSetLocalSheetId()) {
+                       // Given as explicit sheet id
+                       long sheetId = ctName.getLocalSheetId();
+                       if(sheetId >= 0) {
+                               return workbook.getSheetName((int)sheetId);
+                       }
+               } else {
+                       // Is it embeded in the reference itself?
+                       int excl = getReference().indexOf('!');
+                       if(excl > -1) {
+                               return getReference().substring(0, excl);
+                       }
                }
+               
+               // Not given at all
                return null;
        }
 
index b68104a867d5f1f6a55ddc749705bbf4c8f87a03..9509d787cacb968b70fd4f5fd682725155edd161 100644 (file)
@@ -36,6 +36,7 @@ public final class AllXSSFUsermodelTests {
        public static Test suite() {
                TestSuite result = new TestSuite(AllXSSFUsermodelTests.class.getName());
                result.addTestSuite(TestXSSFBorder.class);
+               result.addTestSuite(TestXSSFBugs.class);
                result.addTestSuite(TestXSSFCellFill.class);
                result.addTestSuite(TestXSSFHeaderFooter.class);
                result.addTestSuite(TestXSSFSheetComments.class);
diff --git a/src/ooxml/testcases/org/apache/poi/xssf/usermodel/TestXSSFBugs.java b/src/ooxml/testcases/org/apache/poi/xssf/usermodel/TestXSSFBugs.java
new file mode 100644 (file)
index 0000000..e3d6745
--- /dev/null
@@ -0,0 +1,58 @@
+/* ====================================================================
+   Licensed to the Apache Software Foundation (ASF) under one or more
+   contributor license agreements.  See the NOTICE file distributed with
+   this work for additional information regarding copyright ownership.
+   The ASF licenses this file to You under the Apache License, Version 2.0
+   (the "License"); you may not use this file except in compliance with
+   the License.  You may obtain a copy of the License at
+
+       http://www.apache.org/licenses/LICENSE-2.0
+
+   Unless required by applicable law or agreed to in writing, software
+   distributed under the License is distributed on an "AS IS" BASIS,
+   WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+   See the License for the specific language governing permissions and
+   limitations under the License.
+==================================================================== */
+
+package org.apache.poi.xssf.usermodel;
+
+import java.io.File;
+
+import junit.framework.TestCase;
+
+public class TestXSSFBugs extends TestCase {
+       private String getFilePath(String file) {
+               File xml = new File(
+                               System.getProperty("HSSF.testdata.path") +
+                               File.separator + file
+               );
+               assertTrue(xml.exists());
+               
+               return xml.toString();
+       }
+       
+       /**
+        * Named ranges had the right reference, but
+        *  the wrong sheet name
+        */
+       public void test45430() throws Exception {
+               XSSFWorkbook wb = new XSSFWorkbook(getFilePath("45430.xlsx"));
+               assertEquals(3, wb.getNumberOfNames());
+               
+               assertEquals(0, wb.getNameAt(0).getCTName().getLocalSheetId());
+               assertFalse(wb.getNameAt(0).getCTName().isSetLocalSheetId());
+               assertEquals("SheetA!$A$1", wb.getNameAt(0).getReference());
+               assertEquals("SheetA", wb.getNameAt(0).getSheetName());
+               
+               assertEquals(0, wb.getNameAt(1).getCTName().getLocalSheetId());
+               assertFalse(wb.getNameAt(1).getCTName().isSetLocalSheetId());
+               assertEquals("SheetB!$A$1", wb.getNameAt(1).getReference());
+               assertEquals("SheetB", wb.getNameAt(1).getSheetName());
+               
+               assertEquals(0, wb.getNameAt(2).getCTName().getLocalSheetId());
+               assertFalse(wb.getNameAt(2).getCTName().isSetLocalSheetId());
+               assertEquals("SheetC!$A$1", wb.getNameAt(2).getReference());
+               assertEquals("SheetC", wb.getNameAt(2).getSheetName());
+       }
+}
diff --git a/src/testcases/org/apache/poi/hssf/data/45430.xlsx b/src/testcases/org/apache/poi/hssf/data/45430.xlsx
new file mode 100644 (file)
index 0000000..48af3f9
Binary files /dev/null and b/src/testcases/org/apache/poi/hssf/data/45430.xlsx differ