victorio
victorio

Reputation: 6656

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

Upvotes: 1

Views: 2475

Answers (1)

victorio
victorio

Reputation: 6656

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

Upvotes: 1

Related Questions