IF you want to give it a stab, you can look at the HSSFDateUtil and determine where it strays. Basically excel stores date in double format, so make sure the DateUtil generates the correct double values for known dates.
danny
George Papastamatopoulos wrote:
Hi
Im experiencing some really wierd and frustrating behaviour when dealing with dates.
Whenever I generate a spreadsheet with dates and then open up the spreadsheet, the value displayed in the cell is always one day ahead of the value displayed in the formula bar (the formula bar always displays the correct date). What's wierd is that when I click into the cell edit, and then hit enter, the correct date is then displayed in the cell.
I've searched the archives and have seen similar postings relating to 'how to read dates from excel', but havnt come across any solutions.
I've tried all sorts of combinations and permutations of cell styles, formats etc, but have been unable to solve the problem.
If anyone has suggestions, they would be much appreciated. I've pasted in the latest code snippet below.
Cheers george
....
HSSFCellStyle cellStyle = wb.createCellStyle(); HSSFDataFormat format = wb.createDataFormat();
cellStyle.setDataFormat(HSSFDataFormat.getBuiltinFormat("m/d/yy")); cell.setCellStyle(cellStyle);
Date myDate = myObject.getTheDate();
cell.setCellValue(myDate); cell.setCellValue(HSSFDateUtil.getExcelDate(myDate));
/** * Also tried the following and a bunch of other things */ // cell.setCellType(HSSFCell.CELL_TYPE_NUMERIC); // cell.setCellValue(myDate); ....
__________________________ George Papastamatopoulos
Lawlex Compliance Solutions phone: +61 3 9278 1182 email: [EMAIL PROTECTED] __________________________
--------------------------------------------------------------------- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]
--------------------------------------------------------------------- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]
