Date read error processing poi read excel excel the default text into

    //特殊处理当 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)) {
                    for conversion to date format//
                    Date d = cell.getDateCellValue();
                    DateFormat formater = new SimpleDateFormat("yyyy-MM-dd");
                    return  formater.format(d);
                }else{
                    return      cell.toString();
                }
            } 
            // forced into text 
            cell.setCellType (HSSFCell.CELL_TYPE_STRING);

Note: Forced into text must be placed special treatment process when excel date format after being given the otherwise still

Guess you like

Origin www.cnblogs.com/linxixinxiang/p/11164982.html