]> source.dussan.org Git - poi.git/commitdiff
Make the test related to bug #30978, which shows that named ranges pointing to delete...
authorNick Burch <nick@apache.org>
Mon, 16 Jun 2008 13:39:44 +0000 (13:39 +0000)
committerNick Burch <nick@apache.org>
Mon, 16 Jun 2008 13:39:44 +0000 (13:39 +0000)
git-svn-id: https://svn.apache.org/repos/asf/poi/trunk@668155 13f79535-47bb-0310-9956-ffa450edef68

src/java/org/apache/poi/hssf/record/formula/Area3DPtg.java
src/testcases/org/apache/poi/hssf/data/30978-deleted.xls
src/testcases/org/apache/poi/hssf/usermodel/TestHSSFWorkbook.java

index e8f72e99377d4a9a053268f149aaa684f7825850..5dcada24a3ede12e768cb6d1ebd6de738cee9e58 100644 (file)
@@ -276,8 +276,8 @@ public class Area3DPtg extends OperandPtg implements AreaI {
                        } else {
                                // Normal
                                SheetNameFormatter.appendFormat(retval, sheetName);
-                               retval.append( '!' );
                        }
+                       retval.append( '!' );
                }
                
                // Now the normal area bit
index 1daca5bff70bd033247acbb2fbc20c856512eb09..0a2cabedce3dfb631901b16c51d152bb8db25d7d 100755 (executable)
Binary files a/src/testcases/org/apache/poi/hssf/data/30978-deleted.xls and b/src/testcases/org/apache/poi/hssf/data/30978-deleted.xls differ
index 2fca481481db07221ee1356a6f99c2fca2b3d85c..37359231f8ec28958481e6881f48f67593262e59 100644 (file)
@@ -410,19 +410,26 @@ public final class TestHSSFWorkbook extends TestCase {
      */
     public void testNamesToDeleteSheets() throws Exception {
        HSSFWorkbook b = openSample("30978-deleted.xls");
-       assertEquals(1, b.getNumberOfNames());
+       assertEquals(3, b.getNumberOfNames());
        
-       // Sheet 2 deleted
+       // Sheet 2 is deleted
        assertEquals("Sheet1", b.getSheetName(0));
        assertEquals("Sheet3", b.getSheetName(1));
        
+       Area3DPtg ptg;
+       NameRecord nr;
+       HSSFName n;
+       
+       /* ======= Name pointing to deleted sheet ====== */
+       
        // First at low level
-       NameRecord nr = b.getWorkbook().getNameRecord(0);
+       nr = b.getWorkbook().getNameRecord(0);
        assertEquals("On2", nr.getNameText());
+       assertEquals(0, nr.getIndexToSheet());
        assertEquals(1, nr.getExternSheetNumber());
        assertEquals(1, nr.getNameDefinition().size());
        
-       Area3DPtg ptg = (Area3DPtg)nr.getNameDefinition().get(0);
+       ptg = (Area3DPtg)nr.getNameDefinition().get(0);
        assertEquals(1, ptg.getExternSheetIndex());
        assertEquals(0, ptg.getFirstColumn());
        assertEquals(0, ptg.getFirstRow());
@@ -430,10 +437,56 @@ public final class TestHSSFWorkbook extends TestCase {
        assertEquals(2, ptg.getLastRow());
        
        // Now at high level
-       HSSFName n = b.getNameAt(0);
+       n = b.getNameAt(0);
        assertEquals("On2", n.getNameName());
        assertEquals("", n.getSheetName());
-       assertEquals("#REF$A$1:$A$3", n.getReference());
+       assertEquals("#REF!$A$1:$A$3", n.getReference());
+       
+       
+       /* ======= Name pointing to 1st sheet ====== */
+       
+       // First at low level
+       nr = b.getWorkbook().getNameRecord(1);
+       assertEquals("OnOne", nr.getNameText());
+       assertEquals(0, nr.getIndexToSheet());
+       assertEquals(0, nr.getExternSheetNumber());
+       assertEquals(1, nr.getNameDefinition().size());
+       
+       ptg = (Area3DPtg)nr.getNameDefinition().get(0);
+       assertEquals(0, ptg.getExternSheetIndex());
+       assertEquals(0, ptg.getFirstColumn());
+       assertEquals(2, ptg.getFirstRow());
+       assertEquals(0, ptg.getLastColumn());
+       assertEquals(3, ptg.getLastRow());
+       
+       // Now at high level
+       n = b.getNameAt(1);
+       assertEquals("OnOne", n.getNameName());
+       assertEquals("Sheet1", n.getSheetName());
+       assertEquals("Sheet1!$A$3:$A$4", n.getReference());
+       
+       
+       /* ======= Name pointing to 3rd sheet ====== */
+       
+       // First at low level
+       nr = b.getWorkbook().getNameRecord(2);
+       assertEquals("OnSheet3", nr.getNameText());
+       assertEquals(0, nr.getIndexToSheet());
+       assertEquals(2, nr.getExternSheetNumber());
+       assertEquals(1, nr.getNameDefinition().size());
+       
+       ptg = (Area3DPtg)nr.getNameDefinition().get(0);
+       assertEquals(2, ptg.getExternSheetIndex());
+       assertEquals(0, ptg.getFirstColumn());
+       assertEquals(0, ptg.getFirstRow());
+       assertEquals(0, ptg.getLastColumn());
+       assertEquals(1, ptg.getLastRow());
+       
+       // Now at high level
+       n = b.getNameAt(2);
+       assertEquals("OnSheet3", n.getNameName());
+       assertEquals("Sheet3", n.getSheetName());
+       assertEquals("Sheet3!$A$1:$A$2", n.getReference());
     }
     
     /**