poi excel单元格的校验

switch (cell.getCellType()) {
case HSSFCell.CELL_TYPE_NUMERIC://数值类型
if (0 == cell.getCellType()) {
if (HSSFDateUtil.isCellDateFormatted(cell)) {
Date date = cell.getDateCellValue();
DateFormat formatter = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
cellValue = formatter.format(date);
} else {
         //存储整型类型的数据
double doubleValue = cell.getNumericCellValue();
long longValue = Math.round(doubleValue);
if (Double.parseDouble(longValue + ".0") == doubleValue) {
cellValue = longValue + "";
} else {
cellValue = doubleValue + "";
}
}
}
break;
case HSSFCell.CELL_TYPE_STRING://字符串
cellValue = cell.getStringCellValue();
break;
case HSSFCell.CELL_TYPE_BOOLEAN://boolean值
cellValue = cell.getBooleanCellValue() + "";
break;
case HSSFCell.CELL_TYPE_FORMULA:
cellValue = cell.getCellFormula() + "";
break;
case HSSFCell.CELL_TYPE_BLANK://空值
cellValue = "";
break;
case HSSFCell.CELL_TYPE_ERROR://错误
cellValue = "非法字符";
break;
default:
cellValue = "未知类型";
break;
}
原文地址:https://www.cnblogs.com/lsj-info/p/9476309.html