Edit: To avoid confusions, here's an (again) improved version of my original question:
QUESTION How can I read out the String representation of a cell just the way Microsoft Excel would display it, without knowing respective hard-coding the formatting-settings (but for example using the cell's own formatting settings to format the output).
ANSWER SO FAR This will be no problem if you are using the US-version of excel, for all other versions Apache POI will return strings equivalent to how the US-Version of excel will display it and there is no built-in way in Apache POI to change this. Only way I can confirm is "working" is - as Gagravarr suggested - to switch the language on my Mac to US/EN. Then Apache POI and Excel will deliver the same result. Which is kind of a inverse solution.
The problem is: A cell is displayed like 01.12.13
in the german version of excel, but since it's formatted as a Date
HSSFCell cell = (HSSFCell) cellIter.next();
HSSFDataFormatter formatter=new HSSFDataFormatter();
String val=formatter.formatCellValue(cell)
gives me a val of 21/01/13
.
the original question was:
I am having a xlsx file containing date fields that are displayed in Excel like
01.12.13
using the format setting of the cell TT.MM.JJ
If I read the same file with apache poi, getting the cell and format à la
HSSFCell cell = (HSSFCell) cellIter.next();
HSSFDataFormatter formatter=new HSSFDataFormatter();
String val=formatter.formatCellValue(cell)
(with cellIter
being a valid Iterator of course, simplified example)
my val
turns out to be 21/01/13
. As I understand the HSFDataFormatter's method formatCellValue() should return a String of the value formatted with the cell's format setting.
Does anybody know how I can get the val to contain the same format as in Excel?
I appreciate any help! Thank you!