https://issues.apache.org/bugzilla/show_bug.cgi?id=54705
Bug ID: 54705
Summary: Date cell formats are lost after getting cell comment
Product: POI
Version: 3.9
Hardware: PC
OS: Linux
Status: NEW
Severity: major
Priority: P2
Component: HSSF
Assignee: [email protected]
Reporter: [email protected]
Classification: Unclassified
I'm seeing a very strange problem where cells containing dates become
unreadable after certain operations on certain spreadsheet. The following unit
tests reproduces the problem consistently with a specific spreadsheet.
Unfortunately this contains confidential data so I can't provide this. Also, I
can't create a spreadsheet with the sensitive data removed, as the problem goes
away as soon as the spreadsheet is re-saved from Excel!
The test looks as follows:
public void testGetCellFormat() throws Exception {
try (InputStream inputStream = getClass().getResourceAsStream(
"spreadsheet.xls")) {
Workbook workbook = WorkbookFactory.create(inputStream);
CellStyle styleBefore =
workbook.getSheetAt(0).getRow(7).getCell(7).getCellStyle();
String dateFormatBefore = styleBefore.getDataFormatString();
int dateFormatIndexBefore = styleBefore.getDataFormat();
assertNull("Randomly chosen cell has no comment",
workbook.getSheetAt(0).getRow(0).getCell(0).getCellComment());
CellStyle styleAfter =
workbook.getSheetAt(0).getRow(7).getCell(7).getCellStyle();
String dateFormatAfter = styleAfter.getDataFormatString();
int dateFormatIndexAfter = styleAfter.getDataFormat();
assertEquals("Should be the same",
dateFormatBefore, dateFormatAfter);
assertEquals("Should be the same",
dateFormatIndexBefore, dateFormatIndexAfter);
}
}
This fails on the first assertion with the error: "expected:<[M/d/yyyy
hh:mm:ss ]> but was:<[General]>"
Basically, the date format of the cell is OK before the call to
getCellComment(), but consistently returns the wrong result after (it then
returns "General"). Note that getCellComment() is called on an unrelated cell!
And the cell format is broken on ALL cells in the spreadsheet after this call.
--
You are receiving this mail because:
You are the assignee for the bug.
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]