简体   繁体   中英

How to read a time format from xls/xlsx by Apache POI 3.9?

I have a cell with the 1:20 time value (1:20:00) . How can I read it by apache poi 3.9 ? My code is checking two cell types, and when it reads the time value, it goes to the CELL_TYPE_NUMERIC , and the 1:20 will be 0 . How could I read the exactly 1:20 ? Thank you!

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

I did it!!

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;
}

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM