You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@poi.apache.org by Giorgio Carchedi <gc...@steponweb.it> on 2011/04/15 14:26:57 UTC

Date format problem

Hi,

I'm reading a xls file containing a cell with custom format

in Excel, this cell content appears like
01/01/1900 0.00
and has a format
dd/mm/yyyy h.mm (custom format not date format)


With Apache POI, When i get content with cell.getDateCellValue(), I obtain
the correct value:   Mon Jan 01 00:00:00 CET 1900

But when I try to get it as a string with
new HSSFDataFormatter().formatCellValue(cell)
I obtain the ambiguous value:  1/1/00 0:00  (refer to year 2000 ?) with a
wrong format.

Actually if I ask the cell DateFormat  with
cell.getCellStyle().getDataFormat(), Apache POI returns a format index of
22 and a format string of m/d/yy h:mm.
instead of dd/mm/yyyy hh.mm

How can I automatically read the correct string cell value as well as
appears in excel,
without getting the java Date Object and formatting it by hand?


Thanks
Giorgio




---------------------------------------------------------------------
To unsubscribe, e-mail: user-unsubscribe@poi.apache.org
For additional commands, e-mail: user-help@poi.apache.org


Re: Date format problem

Posted by Nick Burch <ni...@alfresco.com>.
On Fri, 15 Apr 2011, Giorgio Carchedi wrote:
> Actually if I ask the cell DateFormat with 
> cell.getCellStyle().getDataFormat(), Apache POI returns a format index 
> of 22 and a format string of m/d/yy h:mm. instead of dd/mm/yyyy hh.mm

What version of POI are you using? 22 is a built in style, and used not to 
be changable. Recent versions of excel started supporting overriding built 
in styles on a per file bases, and it was quite recent that we started 
supporting this. Maybe you're on a version of POI that predates this 
support?

Nick

---------------------------------------------------------------------
To unsubscribe, e-mail: user-unsubscribe@poi.apache.org
For additional commands, e-mail: user-help@poi.apache.org