Yeah, I know the dates are a little off at the moment, and is related to http://nagoya.apache.org/bugzilla/show_bug.cgi?id=19792. Currently working on other parts of HSSF but I will try to address it within the "soon" timeframe.

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]



Reply via email to