aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorNick Burch <nick@apache.org>2010-08-03 15:29:56 +0000
committerNick Burch <nick@apache.org>2010-08-03 15:29:56 +0000
commit452fa021823a9ebe51068f92885a26a93cd84bf6 (patch)
treead6426b92c2288f2632c86c8f6c6925340fb3742
parent620eb2179606227b35dc81ec625c2dc5eb61baf2 (diff)
downloadpoi-452fa021823a9ebe51068f92885a26a93cd84bf6.tar.gz
poi-452fa021823a9ebe51068f92885a26a93cd84bf6.zip
Fix bug #49689 - Allow the setting of user style names on newly created HSSF cell styles
git-svn-id: https://svn.apache.org/repos/asf/poi/trunk@981930 13f79535-47bb-0310-9956-ffa450edef68
-rw-r--r--src/documentation/content/xdocs/status.xml1
-rw-r--r--src/java/org/apache/poi/hssf/usermodel/HSSFCellStyle.java4
-rw-r--r--src/testcases/org/apache/poi/hssf/usermodel/TestBugs.java34
3 files changed, 38 insertions, 1 deletions
diff --git a/src/documentation/content/xdocs/status.xml b/src/documentation/content/xdocs/status.xml
index 085fc30e20..3c6ba2742c 100644
--- a/src/documentation/content/xdocs/status.xml
+++ b/src/documentation/content/xdocs/status.xml
@@ -34,6 +34,7 @@
<changes>
<release version="3.7-beta2" date="2010-??-??">
+ <action dev="POI-DEVELOPERS" type="fix">49689 - Allow the setting of user style names on newly created HSSF cell styles</action>
<action dev="POI-DEVELOPERS" type="add">Make it easier to tell which content types each POIXMLTextExtractor handles</action>
<action dev="POI-DEVELOPERS" type="fix">49649 - Added clone support for UserSView* and Feat* families of records</action>
<action dev="POI-DEVELOPERS" type="fix">49653 - Support for escaped unicode characters in Shared String Table</action>
diff --git a/src/java/org/apache/poi/hssf/usermodel/HSSFCellStyle.java b/src/java/org/apache/poi/hssf/usermodel/HSSFCellStyle.java
index fbf2a868c1..d65cb4ebce 100644
--- a/src/java/org/apache/poi/hssf/usermodel/HSSFCellStyle.java
+++ b/src/java/org/apache/poi/hssf/usermodel/HSSFCellStyle.java
@@ -778,7 +778,9 @@ public final class HSSFCellStyle implements CellStyle {
if(sr == null) {
sr = _workbook.createStyleRecord(_index);
}
- if(sr.isBuiltin()) {
+ // All Style records start as "builtin", but generally
+ // only 20 and below really need to be
+ if(sr.isBuiltin() && _index <= 20) {
throw new IllegalArgumentException("Unable to set user specified style names for built in styles!");
}
sr.setName(styleName);
diff --git a/src/testcases/org/apache/poi/hssf/usermodel/TestBugs.java b/src/testcases/org/apache/poi/hssf/usermodel/TestBugs.java
index 4afa0a7cbe..7d8c27a6f4 100644
--- a/src/testcases/org/apache/poi/hssf/usermodel/TestBugs.java
+++ b/src/testcases/org/apache/poi/hssf/usermodel/TestBugs.java
@@ -1803,4 +1803,38 @@ if(1==2) {
assertEquals(0xff, rotated.getCellStyle().getRotation());
assertEquals(0xff, nc.getCellStyle().getRotation());
}
+
+ /**
+ * Setting the user style name on custom styles
+ */
+ public void test49689() throws Exception {
+ HSSFWorkbook wb = new HSSFWorkbook();
+ HSSFSheet s = wb.createSheet("Test");
+ HSSFRow r = s.createRow(0);
+ HSSFCell c = r.createCell(0);
+
+ HSSFCellStyle cs1 = wb.createCellStyle();
+ HSSFCellStyle cs2 = wb.createCellStyle();
+ HSSFCellStyle cs3 = wb.createCellStyle();
+
+ assertEquals(21, cs1.getIndex());
+ cs1.setUserStyleName("Testing");
+
+ assertEquals(22, cs2.getIndex());
+ cs2.setUserStyleName("Testing 2");
+
+ assertEquals(23, cs3.getIndex());
+ cs3.setUserStyleName("Testing 3");
+
+ // Set one
+ c.setCellStyle(cs1);
+
+ // Write out and read back
+ wb = writeOutAndReadBack(wb);
+
+ // Re-check
+ assertEquals("Testing", wb.getCellStyleAt((short)21).getUserStyleName());
+ assertEquals("Testing 2", wb.getCellStyleAt((short)22).getUserStyleName());
+ assertEquals("Testing 3", wb.getCellStyleAt((short)23).getUserStyleName());
+ }
}