poi 读取excel 将 excel默认转化为 text时 日期读取出错处理

    //特殊处理当 excel为 日期格式时的处理
            if ("yyyy/mm;@".equals(cell.getCellStyle().getDataFormatString())
                    || "m/d/yy".equals(cell.getCellStyle().getDataFormatString())
                    || "yy/m/d".equals(cell.getCellStyle().getDataFormatString())
                    || "mm/dd/yy".equals(cell.getCellStyle().getDataFormatString())
                    || "dd-mmm-yy".equals(cell.getCellStyle().getDataFormatString())
                    || "yyyy/m/d".equals(cell.getCellStyle().getDataFormatString())) {
                if (DateUtil.isCellDateFormatted(cell)) {
                    // 用于转化为日期格式
                    Date d = cell.getDateCellValue();
                    DateFormat formater = new SimpleDateFormat("yyyy-MM-dd");
                    return  formater.format(d);
                }else{
                    return      cell.toString();
                }
            } else{ 
          return cell.toString();
       }
//强制转化为 文本 cell.setCellType(HSSFCell.CELL_TYPE_STRING);

注意 :强制转化为 文本  一定要放到  特殊处理当 excel为 日期格式时的处理 之后 否则依旧报错

posted @ 2019-07-10 16:47  我爱香香  阅读(917)  评论(0编辑  收藏  举报