<changes>
<release version="3.8-beta4" date="2011-??-??">
+ <action dev="poi-developers" type="fix">49564 - Fixed default behaviour of XSSFCellStyle.getLocked() </action>
<action dev="poi-developers" type="fix">48314 - Fixed setting column and row breaks in XSSF</action>
<action dev="poi-developers" type="add">51424 - Ignore exceptions in ParagraphSprmUncompressor</action>
<action dev="poi-developers" type="fix">51415 - Fixed Workbook.createSheet(sheetName) to truncate names longer than 31 characters</action>
* @return boolean - whether the cell using this style is hidden
*/
public boolean getHidden() {
- return getCellProtection().getHidden();
+ if (!_cellXf.isSetProtection() || !_cellXf.getProtection().isSetHidden()) {
+ return false;
+ }
+ return _cellXf.getProtection().getHidden();
}
/**
* @return whether the cell using this style are locked
*/
public boolean getLocked() {
- return getCellProtection().getLocked();
+ if (!_cellXf.isSetProtection() || !_cellXf.getProtection().isSetLocked()) {
+ return true;
+ }
+ return _cellXf.getProtection().getLocked();
}
/**
* @param hidden - whether the cell using this style should be hidden
*/
public void setHidden(boolean hidden) {
- getCellProtection().setHidden(hidden);
+ if (!_cellXf.isSetProtection()) {
+ _cellXf.addNewProtection();
+ }
+ _cellXf.getProtection().setHidden(hidden);
}
/**
* @param locked - whether the cell using this style should be locked
*/
public void setLocked(boolean locked) {
- getCellProtection().setLocked(locked);
+ if (!_cellXf.isSetProtection()) {
+ _cellXf.addNewProtection();
+ }
+ _cellXf.getProtection().setLocked(locked);
}
/**
return (int) _cellStyleXf.getFontId();
}
- /**
- * get a cellProtection from the supplied XML definition
- * @return CTCellProtection
- */
- private CTCellProtection getCellProtection() {
- if (_cellXf.getProtection() == null) {
- _cellXf.addNewProtection();
- }
- return _cellXf.getProtection();
- }
-
/**
* get the cellAlignment object to use for manage alignment
* @return XSSFCellAlignment - cell alignment
public void testGetSetHidden() {
assertFalse(cellStyle.getHidden());
- cellXf.getProtection().setHidden(true);
+ cellStyle.setHidden(true);
assertTrue(cellStyle.getHidden());
cellStyle.setHidden(false);
assertFalse(cellStyle.getHidden());
}
public void testGetSetLocked() {
- assertFalse(cellStyle.getLocked());
- cellXf.getProtection().setLocked(true);
+ assertTrue(cellStyle.getLocked());
+ cellStyle.setLocked(true);
assertTrue(cellStyle.getLocked());
cellStyle.setLocked(false);
assertFalse(cellStyle.getLocked());
assertEquals(Cell.CELL_TYPE_ERROR, cell2.getCellType());
assertEquals(ErrorConstants.ERROR_DIV_0, cell2.getErrorCellValue());
}
+
+ public void testDefaultStyleProperties() {
+ Workbook wb = _testDataProvider.createWorkbook();
+
+ Cell cell = wb.createSheet("Sheet1").createRow(0).createCell(0);
+ CellStyle style = cell.getCellStyle();
+
+ assertTrue(style.getLocked());
+ assertFalse(style.getHidden());
+ assertEquals(0, style.getIndention());
+ assertEquals(0, style.getFontIndex());
+ assertEquals(0, style.getAlignment());
+ assertEquals(0, style.getDataFormat());
+ assertEquals(false, style.getWrapText());
+
+ CellStyle style2 = wb.createCellStyle();
+ assertTrue(style2.getLocked());
+ assertFalse(style2.getHidden());
+ style2.setLocked(false);
+ style2.setHidden(true);
+ assertFalse(style2.getLocked());
+ assertTrue(style2.getHidden());
+
+ wb = _testDataProvider.writeOutAndReadBack(wb);
+ cell = wb.getSheetAt(0).getRow(0).getCell(0);
+ style = cell.getCellStyle();
+ assertFalse(style2.getLocked());
+ assertTrue(style2.getHidden());
+
+ style2.setLocked(true);
+ style2.setHidden(false);
+ assertTrue(style2.getLocked());
+ assertFalse(style2.getHidden());
+ }
+
}