繁体   English   中英

如何通过Apache POI 3.9从xls / xlsx读取时间格式?

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

我有一个具有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;
}

我做的!!

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

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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