我正在使用 POI HSSF API 进行 Java 中的 excel 操作。我的一个 Excel 单元格中有一个日期值“2009 年 8 月 1 日”,当我尝试使用 HSSF API 读取该值时,它会将单元格类型检测为数字并返回我的日期的“双倍”值。请参阅下面的示例代码:
cell = row.getCell(); // date in the cell '8/1/2009'
switch (cell.getCellType()) {
case HSSFCell.CELL_TYPE_STRING:
cellValue = cell.getRichStringCellValue().getString();
break;
case HSSFCell.CELL_TYPE_NUMERIC:
cellValue = new Double(cell.getNumericCellValue()).toString();
break;
default:
}
Cell.getCellType() 返回 NUMERIC_TYPE,因此此代码将日期转换为双倍!:(
有什么方法可以读取 HSSF POI 中的日期!?