poi-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Nick Burch <n...@torchbox.com>
Subject RE: HSSFCell Time Code String Treated as Date/Numeric
Date Mon, 10 Dec 2007 18:54:55 GMT
On Mon, 10 Dec 2007, richard head wrote:
> We receive about 100 spreadsheets from 3rd parties, I think getting them 
> to add a ' prefix would not go over well.

That's a shame. I expect the other option, of using a sensible file 
format, is also out for the same reason...

> As for the formatting approach, since I also have legitimate dates, I'll 
> have to convert to date, check if the year is 1899, if so, I know I'll 
> have a time code and act accordingly.

Another option is to grab the format string for the the cell, and check to 
see if it only has hour+minute+second parts (plus the extra crud that 
format strings seem to accumilate...). Assuming it doesn't have a date 
part, and is a small enough value, you can treat it as a time.

> I'd like to treat everything as strings by converting everything to the 
> format seen by the user. But I don't see a way to use the format 
> returned by 
> HSSFDataFormat.getBuiltinFormat(cell.getCellStyle().getDataFormat()));

Be wary of only considering the built in date formats. That pretty much 
only covers the "built in" formats as of excel 97. If you're using a newer 
version of excel, then most of the "built in" formats from the ui 
perspective are actually stored as custom formats in the file.

Take a look at HSSFDateUtil.isCellDateFormatted(cell) for how to get the 
underlying format string as well as the format id

Nick

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


Mime
View raw message