Background:
I need to export a spreadsheet document with one column containing date formatted data.
I'm currently setting up the workbook style like so:
...
dateTimeStyle = workbook.createCellStyle();
//dateTimeStyle.setDataFormat(HSSFDataFormat.getBuiltinFormat("m/d/yy h:mm"));
dateTimeStyle.setDataFormat((short)0x16);
...
and inserting the data into the cell/setting the format of the cell like so:
...
if (Date.class.isAssignableFrom(o.getClass())) {
Calendar cal = Calendar.getInstance();
cal.setTime((Date) o);
cell.setCellStyle(dateTimeStyle);
cell.setCellValue(cal);
}
...
Note: According to BuiltinFormats documentation (http://poi.apache.org/apidocs/org/apache/poi/ss/usermodel/BuiltinFormats.html) 0x16 refers to the date format I'm trying to achieve.
The problem I have is that when I open the exported document in Microsoft Office Excel 2007, when I right-click the cell and choose Format cells... it shows the selected cell as having a custom format of dd/mm/yyyy hh:mm
Also, VLOOKUP operations do not work on the column (which I may, admittedly, be doing wrong):
I have a feeling this is due to a misunderstanding of how Excel stores and formats content, and would appreciate any help provided.
Question:
So, how do I correctly format/populate the cell so that Microsoft Excel treats it as a date and VLOOKUPs work etc?
Update: If I open the resulting file in Open Office Calc and choose Format Cells... the format shows up correctly as being Date. Starting to wonder, then, if this is an issue with the POI library and Excel 2007...
Many thanks.