//特殊处理当 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(); } } //强制转化为 文本 cell.setCellType(HSSFCell.CELL_TYPE_STRING);
注意 :强制转化为 文本 一定要放到 特殊处理当 excel为 日期格式时的处理 之后 否则依旧报错