On Thu, 1 Dec 2011, David Beaumont wrote:
On 30 Nov 2011, at 13:05, Nick Burch wrote:
I suspect that your cell is formatted in "default date format" mode,
rather than explicitly being set to the UK date format
(If you open the file on a machine set to a US locale, I strongly suspect
you'll see the US format there too)
Yep I'm sure you're correct. I think the trouble comes from POI assuming
that all locales share the US format and telling POI not to
(DataFormatter(Locale)) doesn't help.
Not quite. The problem is more that Excel will magically ignore certain
formatting strings in the file, and instead use different ones for display
to what gets written out. POI is giving you what your file specified,
which isn't always what you get to see...
The Locale is used by Java once we have a formatting string, to control
how the formatting string is used. It doesn't affect which formatting
string to use, that comes from the file
Otherwise, in POI, just override the date format to be UK style before
formatting.
Do you mean, if the cell is date formatted, get a Java Date using POI's
methods, then format it using SimpleDateFormat? The problem with that is
different date formats are used in different circumstances and I don't
want to override that where the spreadsheet has specifically chosen a
format (e.g. mmm-yy).
You'd need to have a lookup from what the file specifies its format string
to be (eg mmm-dd-yyyy) to what you want displayed to your user (eg
dd-mmm-yyyy).
Or do you mean I can override POI's BuiltinFormats class somehow? I.e.
replace Excel style 14 to be dd/mm/yyyy rather than m/dd/yy. That would
be ideal.
That might work for you, but it isn't something we could change globally
for everyone (tempting as it may be to try to get the Americans using our
style of dates...)
What might be good is if someone could try changing their copy of excel
into all the different locales, and report back what the different format
string change into. We could then provide that lookup list for everyone.
It'd probably be quite a bit of work to do though...
Nick
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]