Dear All,

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>

The format of the cell shown in Excel's is "*14/03/2001". I.e. a date format 
string that takes account of the user's locale.

My code looks like:

String format = cell.getCellStyle().getDataFormatString();
Number numericValue = cell.getNumericCellValue();
CellFormatter formatter;
if (DateUtil.isCellDateFormatted(cell)) {
        formatter = new CellDateFormatter(format);
        numericValue = cell.getNumericCellValue();
}
return formatter.format(numericValue);

The problem seems to be that getDataFormatString returns the American format 
from org.apache.poi.ss.usermodel.BuiltinFormats. I have tried overriding this 
by specifying a locale using org.apache.poi.ss.usermodel.DataFormatter but that 
also seems to use the incorrect format from BuiltinFormats.

I have tested with 3.7 and 3.8 beta 4 as I found some posts in the archive 
suggesting that the problem should be fixed in early betas of 3.8, but I have 
not had any success. Is there any way of working around this problem, besides 
giving up on accessing the string that Excel presents to the user?

Many thanks,
David



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

Reply via email to