OK, I've done a bit of research and I'm going to
answer      my own question for posterity.

Format indexes above 164 are reserved for so-called
user defined formats (although I never defined any of
them, so I'm not sure who the user is who's defining
these), so they don't match any of the built in date
formats (which is what is reported on by the
isCellDateFormatted and isInternalDateFormat methods).

So the only way that I can even semi-reliably work out
whether the current cell holds a date is to do
something like the following:

(...some code to open a workbook into a variable
called wb)

HSSFDataFormat df = wb.createDataFormat() ;

(...some code to read rows and cells, then for each
cell)

short cellFormat =
cell.getCellStyle().getDataFormat();
String formatString = df.getFormat(cellFormat) ;
if ((formatString.indexOf("d") > -1) &&
    (formatString.indexOf("m") > -1) &&
    (formatString.indexOf("y") > -1)) {
     System.out.println("Found date formatted cell") ;
}

The getFormat call will return the picture string
describing the format specified by the given format
index, and the best that I can think to do is to see
if it contains a d, an m and a y, giving me a pretty
good indication that the cell is date formatted.

If anybody else has any better ideas or comments
please let me know.

If anybody's interested, there's an excellent
reference to the Excel file format from the
OpenOffice.org project containing all sorts of useful
information, here:

http://sc.openoffice.org/excelfileformat.pdf


 --- Matthew Keene <[EMAIL PROTECTED]> wrote: 
> I'm trying to work out whether a particular cell 
> contains a date field.  I've been trying to use
> methods from the HSSFDateUtil class to decide
> whether
> or not to treat the data as date or numeric, but I'm
> finding some formats that are dates in my
> spreadsheets, but are not specified in the list of
> formats in the isInternalDateFormat method.  The
> format I'm using is dd-mm-yyyy, which appears to be
> coming through as a format ID of either 167 (0xa7)
> or
> 173 (0xad).  I believe that these are valid date
> formats, can anybody help me out ?
> 
> Matthew Keene
> 
> Find local movie times and trailers on Yahoo!
> Movies.
> http://au.movies.yahoo.com
> 
>
---------------------------------------------------------------------
> To unsubscribe, e-mail:
> [EMAIL PROTECTED]
> For additional commands, e-mail:
> [EMAIL PROTECTED]
> 
>  

Find local movie times and trailers on Yahoo! Movies.
http://au.movies.yahoo.com

---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]

Reply via email to