On Wed, 30 Nov 2011, David Beaumont wrote:
I am trying to use POI to read a UK formatted date string (dd/mm/yyyy) from a cell in an XLSX spreadsheet using POI. Unfortunately, I can't seem to make this work and the formatted string always comes back in US format (m/dd/yy). This is the output from my unit test, in case that makes more sense:

org.junit.ComparisonFailure: expected:<[15/04/20]10> but was:<[4/15/]10>

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)


One option is to explicitly set the format in Excel to be the UK date format. The way to do that varies between excel versions, but it can be done, and the spreadsheet will then show as UK formatted no matter what machine it opens on. At that point, POI (or at least a newer version of it) will then format the cells to the UK format. POI will format it to whatever is set in the file, which may not always be what excel chooses to display!

Otherwise, in POI, just override the date format to be UK style before formatting.

Nick

---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to