读书人

java读取Excel时判断数据的部类

发布时间: 2012-08-01 17:53:40 作者: rapoo

java读取Excel时判断数据的类型
if (cellType == HSSFCell.CELL_TYPE_NUMERIC) {
  Date date = cell.getDateCellValue();
  result = (date.getYear() + 1900) + "-" + (date.getMonth() + 1)
  + "-" + date.getDate();
  } else if (cellType == HSSFCell.CELL_TYPE_STRING) {
  String date = getStringCellValue(cell);
  result = date.replaceAll("[年月]", "-").replace("日", "").trim();
  } else if (cellType == HSSFCell.CELL_TYPE_BLANK) {
  result = "";
  }
  } catch (Exception e) {
  System.out.println("日期格式不正确!");
  e.printStackTrace();
  }

读书人网 >其他相关

热点推荐