Bug 54705 - Date cell formats are lost after getting cell comment
Summary: Date cell formats are lost after getting cell comment
Status: RESOLVED WORKSFORME
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
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2013-03-15 16:38 UTC by Jan
Modified: 2015-06-01 21:24 UTC (History)
1 user (show)



Attachments

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 =
              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.
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.