You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@poi.apache.org by Nishant Rao <kn...@hotmail.com> on 2002/12/09 20:57:12 UTC

date cells

Hi,

I am trying to convert an Excel file to CSV...since some numeric cells might 
be a date, I am using the HSSFDateUtil.isValidExcelDate(double x) helper 
method to determine if its a date and if so doing some additional 
processing.

However, that method seems to return true for any number cell irrespective 
of the value (eg. 5 gives me Thu Jan 04 00:00:00 PST 1900) ?? Am I doing 
anything wrong -- if so, how does one go about correctly extracting a date 
entry ?

btw, I am using POI 1.5.1

thanks

_________________________________________________________________
Tired of spam? Get advanced junk mail protection with MSN 8. 
http://join.msn.com/?page=features/junkmail


Re: date cells

Posted by Avik Sengupta <av...@apache.org>.
This frequently asked question has a frequently answered answer at 
http://jakarta.apache.org/poi/faq.html#faq-6
:)

Regards
-
Avik

On Tue, 2002-12-10 at 05:28, Jim Cobban wrote:
> ----- Original Message -----
> From: "Nishant Rao" <kn...@hotmail.com>
> Subject: date cells
> 
> 
> > I am trying to convert an Excel file to CSV...since some numeric cells
> might
> > be a date, I am using the HSSFDateUtil.isValidExcelDate(double x) helper
> > method to determine if its a date and if so doing some additional
> > processing.
> 
> I haven't tried this myself, but you might try wandering through the format
> information on the cell.  As you will see when you view the cell information
> from Excel itself there is no such thing as a "Date" cell.  Rather there are
> cells which are formatted as dates either because date formatting was
> explicitly chosen, or because a value that looks like a date was entered
> into a cell with general formatting.
> 
> Try using NumberRecord.getXFIndex() to locate the instance of
> ExtendedFormatRecord.  Then getFormatIndex() to locate an instance of
> FormatRecord.  Here you can either look at the format string itself, or you
> can try getIndexCode which says that it returns the built-in format index.
> However the index codes are not documented on the POI web site, so you
> either have to get PG 317 Microsoft Excel 97 Developer's Kit (ISBN:
> 1-57231-498-2) or else play around with a spreadsheet that has known format
> types to see what you get back.
> 
> 
> --
> To unsubscribe, e-mail:   <ma...@jakarta.apache.org>
> For additional commands, e-mail: <ma...@jakarta.apache.org>
> 




Re: date cells

Posted by Jim Cobban <jc...@magma.ca>.
----- Original Message -----
From: "Nishant Rao" <kn...@hotmail.com>
Subject: date cells


> I am trying to convert an Excel file to CSV...since some numeric cells
might
> be a date, I am using the HSSFDateUtil.isValidExcelDate(double x) helper
> method to determine if its a date and if so doing some additional
> processing.

I haven't tried this myself, but you might try wandering through the format
information on the cell.  As you will see when you view the cell information
from Excel itself there is no such thing as a "Date" cell.  Rather there are
cells which are formatted as dates either because date formatting was
explicitly chosen, or because a value that looks like a date was entered
into a cell with general formatting.

Try using NumberRecord.getXFIndex() to locate the instance of
ExtendedFormatRecord.  Then getFormatIndex() to locate an instance of
FormatRecord.  Here you can either look at the format string itself, or you
can try getIndexCode which says that it returns the built-in format index.
However the index codes are not documented on the POI web site, so you
either have to get PG 317 Microsoft Excel 97 Developer's Kit (ISBN:
1-57231-498-2) or else play around with a spreadsheet that has known format
types to see what you get back.