I want to load Excel files with exactly the same formatting as displayed in Excel. However I am struggling to get the Date correctly 100% of time.
I have tried to use DataFormatter mentioned here: how to read exact cell content of excel file in apache POI but with no luck.
My code is:
switch (cell.getCellType()) {
(...)
case NUMERIC:
if (DateUtil.isCellDateFormatted(cell)) {
DataFormatter df = new DataFormatter()
data.get(i).add(df.formatCellValue(cell));
} else {
data.get(i).add(String.valueOf(cell));
}
break;
(...)
Examples:
In Excel date is formatted using the pattern dd.MM.yyyy (28.12.2018), but application reads it as MM/dd/yy (12/28/18) which is wrong;
In Excel date is formatted using the pattern yyyy-MM-dd (2018-12-28) and application reads it as yyyy-MM-dd (2019-12-28) which is fine.
How to make it read the Date as it appears in Excel no matter which formatting is chosen?