1

我有一个带有1:20时间值的单元格(1:20:00)。我如何通过apache poi 3.9阅读它?我的代码正在检查两种单元格类型,当它读取时间值时,它会转到CELL_TYPE_NUMERIC,而1:20将是0。我怎么能准确地阅读1:20?谢谢!

switch (cell.getCellType()) {
    case HSSFCell.CELL_TYPE_NUMERIC:
        cellValue = String.valueOf((int) (cell.getNumericCellValue()));
        break;
    case HSSFCell.CELL_TYPE_STRING:
        cellValue = cell.getStringCellValue();
         break;
}
4

1 回答 1

1

我做的!!

switch (cell.getCellType()) {
    case HSSFCell.CELL_TYPE_NUMERIC:
        if(DateUtil.isCellDateFormatted(cell)) {
            cellValue = new DataFormatter().formatCellValue(cell);
        } else {
            cellValue = String.valueOf((int) (cell.getNumericCellValue()));
        }
        break;
    case HSSFCell.CELL_TYPE_STRING:
        cellValue = cell.getStringCellValue();
        break;
}
于 2013-09-23T11:36:41.017 回答