Im using an xlsx file that contains a DATE(year, month, day)
formula within a cell. This cell is formatted as date, so Excel/OpenOffice shows the proper date.
e.g. the cell content is '=DATE(2013;1;1)'
which produces : '01.01.2013'
So far - so good.
When reading this file with the poi library I do:
XSSFWorkbook workbook = new XSSFWorkbook(new FileInputStream(new File("/home/detlef/temp/test.xlsx")));
XSSFSheet sheet = workbook.getSheet("Sheet A");
XSSFCell cell = sheet.getRow(0).getCell(0);
System.out.println(cell.getDateCellValue());
This will print out:
Sun Dec 31 00:00:00 CET 1899
I am using POI 3.9.
Can anybody tell me why this happens?
Found a way to do it:
if (cell.getCellType() == Cell.CELL_TYPE_FORMULA) {
FormulaEvaluator evaluator = workbook.getCreationHelper().createFormulaEvaluator();
CellValue evaluate = evaluator.evaluate(cell);
Date date = DateUtil.getJavaDate(evaluate.getNumberValue());
System.out.println(date);
}
That produces:
Tue Jan 01 00:00:00 CET 2013
Thanks anyway.