Bug 54705 - Date cell formats are lost after getting cell comment
Summary: Date cell formats are lost after getting cell comment
Alias: None
Product: POI
Classification: Unclassified
Component: HSSF (show other bugs)
Version: 3.9-FINAL
Hardware: PC Linux
: P2 major (vote)
Target Milestone: ---
Assignee: POI Developers List
Depends on:
Reported: 2013-03-15 16:38 UTC by Jan
Modified: 2015-06-01 21:24 UTC (History)
1 user (show)


Note You need to log in before you can comment on or make changes to this bug.
Description Jan 2013-03-15 16:38:55 UTC
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 =
            String dateFormatBefore = styleBefore.getDataFormatString();
            int dateFormatIndexBefore = styleBefore.getDataFormat();
            assertNull("Randomly chosen cell has no comment", 
            CellStyle styleAfter = 
            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.
Comment 1 Dominik Stadler 2013-05-25 21:42:42 UTC
This works for me both with a sample XLS and XLSX file. Can you please attach the actual file "spreadsheet.xls" to let us reproduce the problem?
Comment 2 Dominik Stadler 2015-06-01 21:24:24 UTC
No update for a long time, thus resolving this bug now.