Bug 49564 - Fixed default behaviour of XSSFCellStyle.getLocked()

git-svn-id: https://svn.apache.org/repos/asf/poi/trunk@1139288 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
Yegor Kozlov 2011-06-24 13:06:04 +00:00
parent 26c6241c8a
commit b8df0e686b
4 changed files with 55 additions and 18 deletions

View File

@ -34,6 +34,7 @@
<changes> <changes>
<release version="3.8-beta4" date="2011-??-??"> <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="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="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> <action dev="poi-developers" type="fix">51415 - Fixed Workbook.createSheet(sheetName) to truncate names longer than 31 characters</action>

View File

@ -565,7 +565,10 @@ public class XSSFCellStyle implements CellStyle {
* @return boolean - whether the cell using this style is hidden * @return boolean - whether the cell using this style is hidden
*/ */
public boolean getHidden() { public boolean getHidden() {
return getCellProtection().getHidden(); if (!_cellXf.isSetProtection() || !_cellXf.getProtection().isSetHidden()) {
return false;
}
return _cellXf.getProtection().getHidden();
} }
/** /**
@ -619,7 +622,10 @@ public class XSSFCellStyle implements CellStyle {
* @return whether the cell using this style are locked * @return whether the cell using this style are locked
*/ */
public boolean getLocked() { public boolean getLocked() {
return getCellProtection().getLocked(); if (!_cellXf.isSetProtection() || !_cellXf.getProtection().isSetLocked()) {
return true;
}
return _cellXf.getProtection().getLocked();
} }
/** /**
@ -1169,7 +1175,10 @@ public class XSSFCellStyle implements CellStyle {
* @param hidden - whether the cell using this style should be hidden * @param hidden - whether the cell using this style should be hidden
*/ */
public void setHidden(boolean hidden) { public void setHidden(boolean hidden) {
getCellProtection().setHidden(hidden); if (!_cellXf.isSetProtection()) {
_cellXf.addNewProtection();
}
_cellXf.getProtection().setHidden(hidden);
} }
/** /**
@ -1218,7 +1227,10 @@ public class XSSFCellStyle implements CellStyle {
* @param locked - whether the cell using this style should be locked * @param locked - whether the cell using this style should be locked
*/ */
public void setLocked(boolean locked) { public void setLocked(boolean locked) {
getCellProtection().setLocked(locked); if (!_cellXf.isSetProtection()) {
_cellXf.addNewProtection();
}
_cellXf.getProtection().setLocked(locked);
} }
/** /**
@ -1388,17 +1400,6 @@ public class XSSFCellStyle implements CellStyle {
return (int) _cellStyleXf.getFontId(); 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 * get the cellAlignment object to use for manage alignment
* @return XSSFCellAlignment - cell alignment * @return XSSFCellAlignment - cell alignment

View File

@ -526,15 +526,15 @@ public class TestXSSFCellStyle extends TestCase {
public void testGetSetHidden() { public void testGetSetHidden() {
assertFalse(cellStyle.getHidden()); assertFalse(cellStyle.getHidden());
cellXf.getProtection().setHidden(true); cellStyle.setHidden(true);
assertTrue(cellStyle.getHidden()); assertTrue(cellStyle.getHidden());
cellStyle.setHidden(false); cellStyle.setHidden(false);
assertFalse(cellStyle.getHidden()); assertFalse(cellStyle.getHidden());
} }
public void testGetSetLocked() { public void testGetSetLocked() {
assertFalse(cellStyle.getLocked()); assertTrue(cellStyle.getLocked());
cellXf.getProtection().setLocked(true); cellStyle.setLocked(true);
assertTrue(cellStyle.getLocked()); assertTrue(cellStyle.getLocked());
cellStyle.setLocked(false); cellStyle.setLocked(false);
assertFalse(cellStyle.getLocked()); assertFalse(cellStyle.getLocked());

View File

@ -544,4 +544,39 @@ public abstract class BaseTestCell extends TestCase {
assertEquals(Cell.CELL_TYPE_ERROR, cell2.getCellType()); assertEquals(Cell.CELL_TYPE_ERROR, cell2.getCellType());
assertEquals(ErrorConstants.ERROR_DIV_0, cell2.getErrorCellValue()); 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());
}
} }