]> source.dussan.org Git - poi.git/commitdiff
added HSSFName.isDeleted() to check if the name points to cell that no longer exists
authorYegor Kozlov <yegor@apache.org>
Sat, 17 May 2008 14:00:30 +0000 (14:00 +0000)
committerYegor Kozlov <yegor@apache.org>
Sat, 17 May 2008 14:00:30 +0000 (14:00 +0000)
git-svn-id: https://svn.apache.org/repos/asf/poi/trunk@657355 13f79535-47bb-0310-9956-ffa450edef68

src/documentation/content/xdocs/changes.xml
src/documentation/content/xdocs/hssf/quick-guide.xml
src/documentation/content/xdocs/status.xml
src/java/org/apache/poi/hssf/usermodel/HSSFName.java
src/testcases/org/apache/poi/hssf/usermodel/TestNamedRange.java

index e837cb027c4ea201e881d39414f6a0480417566d..65fe1e25c4919e1213c44660fee7f7002a0ec11b 100644 (file)
@@ -37,6 +37,7 @@
 
                <!-- Don't forget to update status.xml too! -->
         <release version="3.1-beta2" date="2008-05-??">
+           <action dev="POI-DEVELOPERS" type="fix">24207 - added HSSFName.isDeleted() to check if the name points to cell that no longer exists</action>
            <action dev="POI-DEVELOPERS" type="fix">40414 - fixed selected/active sheet after removing sheet from workbook</action>
            <action dev="POI-DEVELOPERS" type="fix">44523 - fixed workbook sheet selection and focus</action>
            <action dev="POI-DEVELOPERS" type="fix">45000 - Fixed NPE in ListLevel when numberText is null</action>
index 66da60489237b7d74d36238ddbc91ca4b33d5d54..28e2374338743d514fa0155552b5c64a04dd59a9 100644 (file)
@@ -1225,7 +1225,19 @@ Examples:
             // Do something with this corner cell
         }
     }
-            </source>
+          </source>
+          <p>
+            Note, when a cell is deleted, Excel does not delete the attached named range. 
+            As result, workbook can contain named ranges that point to cells that no longer exist.
+            You should check the validity of a reference before constructing AreaReference  
+          </p>
+          <source>
+    if(hssfName.isDeleted()){
+      //named range points to a deleted cell. 
+    } else {
+      AreaReference ref = new AreaReference(hssfName.getReference());
+    }
+          </source>
         </section>
         <anchor id="CellComments"/>
         <section><title>Cell Comments</title>
index 0d87990cdbbc786ad7c8f5f0b57d3bac69db026f..28019e68feef91e3fb78fe39b987620e2f3b3e86 100644 (file)
@@ -34,6 +34,7 @@
        <!-- Don't forget to update changes.xml too! -->
     <changes>
         <release version="3.1-beta2" date="2008-05-??">
+           <action dev="POI-DEVELOPERS" type="fix">24207 - added HSSFName.isDeleted() to check if the name points to cell that no longer exists</action>
            <action dev="POI-DEVELOPERS" type="fix">40414 - fixed selected/active sheet after removing sheet from workbook</action>
            <action dev="POI-DEVELOPERS" type="fix">44523 - fixed workbook sheet selection and focus</action>
            <action dev="POI-DEVELOPERS" type="fix">45000 - Fixed NPE in ListLevel when numberText is null</action>
index 91b3fcd0f1c15fb009377210826fe49027971e1c..e24ca23ea85fbc48f45d945a0300db6de803fa22 100644 (file)
@@ -139,4 +139,13 @@ public class HSSFName {
 
     }
 
+    /**
+     * Tests if this name points to a cell that no longer exists
+     *
+     * @return true if the name refers to a deleted cell, false otherwise
+     */
+    public boolean isDeleted(){
+        String ref = getReference();
+        return "#REF!".endsWith(ref);
+    }
 }
index 98500960da101bbc503a8dd36982e27d4ef305a4..b3d08bf7244fbfefd6253522033413ed0f26dc28 100644 (file)
@@ -533,4 +533,28 @@ public final class TestNamedRange extends TestCase {
                String contents = c.getStringCellValue();
                assertEquals("Contents of cell retrieved by its named reference", contents, cvalue);
        }
+
+    public void testDeletedReference() throws Exception {
+        HSSFWorkbook wb = HSSFTestDataSamples.openSampleWorkbook("24207.xls");
+        assertEquals(2, wb.getNumberOfNames());
+
+        HSSFName name1 = wb.getNameAt(0);
+        assertEquals("a", name1.getNameName());
+        assertEquals("Sheet1!$A$1", name1.getReference());
+        AreaReference ref1 = new AreaReference(name1.getReference());
+        assertTrue("Successfully constructed first reference", true);
+
+        HSSFName name2 = wb.getNameAt(1);
+        assertEquals("b", name2.getNameName());
+        assertEquals("#REF!", name2.getReference());
+        assertTrue(name2.isDeleted());
+        try {
+            AreaReference ref2 = new AreaReference(name2.getReference());
+            fail("attempt to supply an invalid reference to AreaReference constructor results in exception");
+        } catch (Exception e){
+            ;
+        }
+
+    }
+
 }