Finish exposing the name of Named Cell Styles via HSSFCellStyle (normally held on the parent style though)

git-svn-id: https://svn.apache.org/repos/asf/poi/trunk@695420 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
Nick Burch 2008-09-15 11:02:18 +00:00
parent d514f9b689
commit 7bd89bc944
4 changed files with 39 additions and 3 deletions

View File

@ -37,6 +37,7 @@
<!-- Don't forget to update status.xml too! -->
<release version="3.1.1-alpha1" date="2008-??-??">
<action dev="POI-DEVELOPERS" type="add">Expose the name of Named Cell Styles via HSSFCellStyle (normally held on the parent style though)</action>
<action dev="POI-DEVELOPERS" type="fix">45978 - Fixed IOOBE in Ref3DPtg.toFormulaString() due eager initialisation of SheetReferences</action>
<action dev="POI-DEVELOPERS" type="add">Made HSSFFormulaEvaluator no longer require initialisation with sheet or row</action>
<action dev="POI-DEVELOPERS" type="add">Extended support for cached results of formula cells</action>

View File

@ -34,6 +34,7 @@
<!-- Don't forget to update changes.xml too! -->
<changes>
<release version="3.1.1-alpha1" date="2008-??-??">
<action dev="POI-DEVELOPERS" type="add">Expose the name of Named Cell Styles via HSSFCellStyle (normally held on the parent style though)</action>
<action dev="POI-DEVELOPERS" type="fix">45978 - Fixed IOOBE in Ref3DPtg.toFormulaString() due eager initialisation of SheetReferences</action>
<action dev="POI-DEVELOPERS" type="add">Made HSSFFormulaEvaluator no longer require initialisation with sheet or row</action>
<action dev="POI-DEVELOPERS" type="add">Extended support for cached results of formula cells</action>

View File

@ -255,6 +255,22 @@ public class HSSFCellStyle
return index;
}
/**
* Return the parent style for this cell style.
* In most cases this will be null, but in a few
* cases there'll be a fully defined parent.
*/
public HSSFCellStyle getParentStyle() {
if(format.getParentIndex() == 0) {
return null;
}
return new HSSFCellStyle(
format.getParentIndex(),
workbook.getExFormatAt(format.getParentIndex()),
workbook
);
}
/**
* set the data format (must be a valid format)
* @see org.apache.poi.hssf.usermodel.HSSFDataFormat

View File

@ -334,10 +334,28 @@ public class TestCellStyle
assertEquals(23, cs2.getIndex());
assertEquals(24, cs3.getIndex());
assertNull(cs1.getParentStyle());
assertNotNull(cs2.getParentStyle());
assertNotNull(cs3.getParentStyle());
assertEquals(21, cs2.getParentStyle().getIndex());
assertEquals(22, cs3.getParentStyle().getIndex());
// Now check we can get style records for
// the parent ones
assertNull(wb.getWorkbook().getStyleRecord(15));
assertNull(wb.getWorkbook().getStyleRecord(23));
assertNull(wb.getWorkbook().getStyleRecord(24));
assertNotNull(wb.getWorkbook().getStyleRecord(21));
assertNotNull(wb.getWorkbook().getStyleRecord(22));
// Now check the style names
// assertEquals(null, cs1.getUserStyleName());
// assertEquals("style1", cs2.getUserStyleName());
// assertEquals("style2", cs3.getUserStyleName());
assertEquals(null, cs1.getUserStyleName());
assertEquals(null, cs2.getUserStyleName());
assertEquals(null, cs3.getUserStyleName());
assertEquals("style1", cs2.getParentStyle().getUserStyleName());
assertEquals("style2", cs3.getParentStyle().getUserStyleName());
}
public static void main(String [] ignored_args)