使用ApachePOIJava从Excel获取具有日期公式的单元格的日期值
我试图从excel文件中读取正常单元格值下的所有内容。但当谈到公式,尤其是日期字段时,我无法得到任何日期值 如何在计算的单元格值中检查日期类型??如何获取日期值 我的代码如下使用ApachePOIJava从Excel获取具有日期公式的单元格的日期值,java,excel,excel-formula,apache-poi,Java,Excel,Excel Formula,Apache Poi,我试图从excel文件中读取正常单元格值下的所有内容。但当谈到公式,尤其是日期字段时,我无法得到任何日期值 如何在计算的单元格值中检查日期类型??如何获取日期值 我的代码如下 Cell cell = nextRow.getCell(cellIndex, Row.CREATE_NULL_AS_BLANK); if (cell.getCellType() == Cell.CELL_TYPE_FORMULA) { FormulaEvaluator evaluator = workbook.g
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;
}
}
}
HSSFDateUtil : Helped to solve my issue. my solution is :
case Cell.CELL_TYPE_NUMERIC: {
if (HSSFDateUtil.isCellDateFormatted(cell)) {
Date date = HSSFDateUtil.getJavaDate(formulaValue.getNumberValue());
System.out.println(date);
} else {
System.out.println(cell.getNumericCellValue());
}
break;