0
我试图从excel文件中读取一切正常的单元格值。但是当涉及公式时,特别是日期字段,我无法获取任何日期值。使用Apache POI从Excel获取单元格的日期值Java
我如何检查中评价的CellValue日期类型?以及如何获取日期值?
我的代码如下。
Cell cell = nextRow.getCell(cellIndex, Row.CREATE_NULL_AS_BLANK);
if (cell.getCellType() == Cell.CELL_TYPE_FORMULA) {
FormulaEvaluator evaluator = workbook.getCreationHelper().createFormulaEvaluator();
CellValue formulaValue = evaluator.evaluate(cell);
switch (formulaValue.getCellType()) {
case Cell.CELL_TYPE_NUMERIC: {
int numbericValue = formulaValue.getNumericValue(); // 42909.0
if (isCellDate?) { //What should i check here?
// DATE THINGS
// how to convert numeric value 42909.0 to date??
} else {
// NUMERIC THINGS
}
break;
}
default:
// STRING - ERROR - BLANK - NUMERIC THINGS
break;
}
}
https://poi.apache.org/spreadsheet/quick-guide.html#CellContents –