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
This commit is contained in:
parent
d24ed25318
commit
11a095bb3d
@ -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;
|
||||
|
@ -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());
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user