Background:
I need to export a spreadsheet document with one column containing data in date format.
I am currently customizing the style of the workbook as follows:
... dateTimeStyle = workbook.createCellStyle(); //dateTimeStyle.setDataFormat(HSSFDataFormat.getBuiltinFormat("m/d/yy h:mm")); dateTimeStyle.setDataFormat((short)0x16); ...
and inserting data into the cell / setting the cell format as follows:
... if (Date.class.isAssignableFrom(o.getClass())) { Calendar cal = Calendar.getInstance(); cal.setTime((Date) o); cell.setCellStyle(dateTimeStyle); cell.setCellValue(cal); } ...
Note: According to the documentation of BuiltinFormats ( http://poi.apache.org/apidocs/org/apache/poi/ss/usermodel/BuiltinFormats.html ) 0x16 refers to the date format I'm trying to reach.
The problem is that when I open the exported document in Microsoft Office Excel 2007, when I right-click the cell and select the "Format" cells ... it displays the selected cell as a custom format dd / mm / yyyy hh: mm

Also, VLOOKUP operations do not work on a column (which I admittedly do wrong):

I have a feeling that this is due to a misunderstanding of how Excel stores and formats content, and would be grateful for the help provided.
Question:
So, how to format / populate a cell correctly so that Microsoft Excel treats it as the date and work of VLOOKUP, etc.?
Update:. If I open the resulting file in Open Office Calc and select "Cell Format" ... the format displays correctly as Date. Afraid if this is a problem with the POI library and Excel 2007 ...
Many thanks.
source share