From: Nick Burch Date: Mon, 16 Jun 2008 13:39:44 +0000 (+0000) Subject: Make the test related to bug #30978, which shows that named ranges pointing to delete... X-Git-Tag: REL_3_2_FINAL~286 X-Git-Url: https://source.dussan.org/?a=commitdiff_plain;h=becda4a35ee863210289fc93c2e8f9cbe836773f;p=poi.git Make the test related to bug #30978, which shows that named ranges pointing to deleted sheets is ok, more complete git-svn-id: https://svn.apache.org/repos/asf/poi/trunk@668155 13f79535-47bb-0310-9956-ffa450edef68 --- diff --git a/src/java/org/apache/poi/hssf/record/formula/Area3DPtg.java b/src/java/org/apache/poi/hssf/record/formula/Area3DPtg.java index e8f72e9937..5dcada24a3 100644 --- a/src/java/org/apache/poi/hssf/record/formula/Area3DPtg.java +++ b/src/java/org/apache/poi/hssf/record/formula/Area3DPtg.java @@ -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 diff --git a/src/testcases/org/apache/poi/hssf/data/30978-deleted.xls b/src/testcases/org/apache/poi/hssf/data/30978-deleted.xls index 1daca5bff7..0a2cabedce 100755 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 diff --git a/src/testcases/org/apache/poi/hssf/usermodel/TestHSSFWorkbook.java b/src/testcases/org/apache/poi/hssf/usermodel/TestHSSFWorkbook.java index 2fca481481..37359231f8 100644 --- a/src/testcases/org/apache/poi/hssf/usermodel/TestHSSFWorkbook.java +++ b/src/testcases/org/apache/poi/hssf/usermodel/TestHSSFWorkbook.java @@ -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()); } /**