<!-- 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>
// 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>
<!-- 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>
}
+ /**
+ * 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);
+ }
}
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){
+ ;
+ }
+
+ }
+
}