diff options
author | Nick Burch <nick@apache.org> | 2014-05-29 11:39:50 +0000 |
---|---|---|
committer | Nick Burch <nick@apache.org> | 2014-05-29 11:39:50 +0000 |
commit | 09a9ca7bef7ab2fffcb0a3ca5de71f9f64cd4011 (patch) | |
tree | 58e5ae95cecd593cd6a8bd8cccea66f9fff6bb08 | |
parent | 87d020c03ae18730cb52f1fe5d134e2eba81a140 (diff) | |
download | poi-09a9ca7bef7ab2fffcb0a3ca5de71f9f64cd4011.tar.gz poi-09a9ca7bef7ab2fffcb0a3ca5de71f9f64cd4011.zip |
HSSFCell should follow XSSF, and allow setting a null-style to return to the default style, fixes bug #56572
git-svn-id: https://svn.apache.org/repos/asf/poi/trunk@1598258 13f79535-47bb-0310-9956-ffa450edef68
-rw-r--r-- | src/java/org/apache/poi/hssf/usermodel/HSSFCell.java | 8 | ||||
-rw-r--r-- | src/testcases/org/apache/poi/hssf/usermodel/TestHSSFCell.java | 36 |
2 files changed, 43 insertions, 1 deletions
diff --git a/src/java/org/apache/poi/hssf/usermodel/HSSFCell.java b/src/java/org/apache/poi/hssf/usermodel/HSSFCell.java index a28d023aff..c66cdd3d13 100644 --- a/src/java/org/apache/poi/hssf/usermodel/HSSFCell.java +++ b/src/java/org/apache/poi/hssf/usermodel/HSSFCell.java @@ -899,7 +899,13 @@ public class HSSFCell implements Cell { setCellStyle( (HSSFCellStyle)style ); } public void setCellStyle(HSSFCellStyle style) { - // Verify it really does belong to our workbook + // A style of null means resetting back to the default style + if (style == null) { + _record.setXFIndex((short)0xf); + return; + } + + // Verify the style really does belong to our workbook style.verifyBelongsToWorkbook(_book); short styleIndex; diff --git a/src/testcases/org/apache/poi/hssf/usermodel/TestHSSFCell.java b/src/testcases/org/apache/poi/hssf/usermodel/TestHSSFCell.java index e18eebe90b..078042970f 100644 --- a/src/testcases/org/apache/poi/hssf/usermodel/TestHSSFCell.java +++ b/src/testcases/org/apache/poi/hssf/usermodel/TestHSSFCell.java @@ -459,4 +459,40 @@ public final class TestHSSFCell extends BaseTestCell { cell.setCellValue((String)null); cell.setCellValue((RichTextString)null); } + + public void testSetRemoveStyle() throws Exception { + HSSFWorkbook wb = new HSSFWorkbook(); + HSSFSheet sheet = wb.createSheet(); + HSSFRow row = sheet.createRow(0); + HSSFCell cell = row.createCell(0); + + HSSFCellStyle defaultStyle = wb.getCellStyleAt((short)15); + + // Starts out with the default style + assertEquals(defaultStyle, cell.getCellStyle()); + + // Create some styles, no change + HSSFCellStyle style1 = wb.createCellStyle(); + HSSFCellStyle style2 = wb.createCellStyle(); + style1.setDataFormat((short)2); + style2.setDataFormat((short)3); + + assertEquals(defaultStyle, cell.getCellStyle()); + + // Apply one, changes + cell.setCellStyle(style1); + assertEquals(style1, cell.getCellStyle()); + + // Apply the other, changes + cell.setCellStyle(style2); + assertEquals(style2, cell.getCellStyle()); + + // Remove, goes back to default + cell.setCellStyle(null); + assertEquals(defaultStyle, cell.getCellStyle()); + + // Add back, returns + cell.setCellStyle(style2); + assertEquals(style2, cell.getCellStyle()); + } } |