From: Nick Burch Date: Mon, 15 Sep 2008 11:02:18 +0000 (+0000) Subject: Finish exposing the name of Named Cell Styles via HSSFCellStyle (normally held on... X-Git-Tag: REL_3_2_FINAL~55 X-Git-Url: https://source.dussan.org/?a=commitdiff_plain;h=7bd89bc944ca0a48cd23bdaf52d470c080425330;p=poi.git 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 --- diff --git a/src/documentation/content/xdocs/changes.xml b/src/documentation/content/xdocs/changes.xml index 5ce7097f26..a43864184a 100644 --- a/src/documentation/content/xdocs/changes.xml +++ b/src/documentation/content/xdocs/changes.xml @@ -37,6 +37,7 @@ + Expose the name of Named Cell Styles via HSSFCellStyle (normally held on the parent style though) 45978 - Fixed IOOBE in Ref3DPtg.toFormulaString() due eager initialisation of SheetReferences Made HSSFFormulaEvaluator no longer require initialisation with sheet or row Extended support for cached results of formula cells diff --git a/src/documentation/content/xdocs/status.xml b/src/documentation/content/xdocs/status.xml index 926986edbb..965ceeefa5 100644 --- a/src/documentation/content/xdocs/status.xml +++ b/src/documentation/content/xdocs/status.xml @@ -34,6 +34,7 @@ + Expose the name of Named Cell Styles via HSSFCellStyle (normally held on the parent style though) 45978 - Fixed IOOBE in Ref3DPtg.toFormulaString() due eager initialisation of SheetReferences Made HSSFFormulaEvaluator no longer require initialisation with sheet or row Extended support for cached results of formula cells diff --git a/src/java/org/apache/poi/hssf/usermodel/HSSFCellStyle.java b/src/java/org/apache/poi/hssf/usermodel/HSSFCellStyle.java index f74c38d09e..2afd16d8d1 100644 --- a/src/java/org/apache/poi/hssf/usermodel/HSSFCellStyle.java +++ b/src/java/org/apache/poi/hssf/usermodel/HSSFCellStyle.java @@ -254,6 +254,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) diff --git a/src/testcases/org/apache/poi/hssf/usermodel/TestCellStyle.java b/src/testcases/org/apache/poi/hssf/usermodel/TestCellStyle.java index e2783b4434..a4cf005a0c 100644 --- a/src/testcases/org/apache/poi/hssf/usermodel/TestCellStyle.java +++ b/src/testcases/org/apache/poi/hssf/usermodel/TestCellStyle.java @@ -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)