aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorNick Burch <nick@apache.org>2008-09-15 11:02:18 +0000
committerNick Burch <nick@apache.org>2008-09-15 11:02:18 +0000
commit7bd89bc944ca0a48cd23bdaf52d470c080425330 (patch)
tree87b97af9fc8df17a991ce1ae0885d1971167427a
parentd514f9b689602c73110d5c73b8941829af4c6ec0 (diff)
downloadpoi-7bd89bc944ca0a48cd23bdaf52d470c080425330.tar.gz
poi-7bd89bc944ca0a48cd23bdaf52d470c080425330.zip
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
-rw-r--r--src/documentation/content/xdocs/changes.xml1
-rw-r--r--src/documentation/content/xdocs/status.xml1
-rw-r--r--src/java/org/apache/poi/hssf/usermodel/HSSFCellStyle.java16
-rw-r--r--src/testcases/org/apache/poi/hssf/usermodel/TestCellStyle.java24
4 files changed, 39 insertions, 3 deletions
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 @@
<!-- 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>
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 @@
<!-- 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>
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)