工具类
private static Object getCellFormatValue(Cell cell) {
Object returnValue = null;
if (cell != null || cell.getCellType() != Cell.CELL_TYPE_BLANK) {
switch (cell.getCellType()) {
case Cell.CELL_TYPE_NUMERIC:
Double doubleValue = cell.getNumericCellValue();
String str = doubleValue.toString();
if (str.contains(".0")) {
Date years = getJavaDate(doubleValue);
returnValue = DateFormatUtil.simpleDateFormat.format(years);
} else {
DecimalFormat df = new DecimalFormat("#");
returnValue= df.format(cell.getNumericCellValue());
}
break;
case Cell.CELL_TYPE_STRING:
returnValue = cell.getRichStringCellValue().getString();
break;
case Cell.CELL_TYPE_BOOLEAN:
Boolean booleanValue = cell.getBooleanCellValue();
returnValue = booleanValue.toString();
break;
case Cell.CELL_TYPE_BLANK:
returnValue = "";
break;
case Cell.CELL_TYPE_FORMULA:
returnValue = cell.getCellFormula();
break;
case Cell.CELL_TYPE_ERROR:
returnValue = null;
break;
default:
System.out.println("未知类型");
break;
}
}
System.out.println("转换后:" + returnValue);
return returnValue;
}