poi 4.1 XSSFCell类型无法定义的处理方式
pom文件
<dependency>
<groupId>org.apache.poi</groupId>
<artifactId>poi</artifactId>
<version>4.1.0</version>
</dependency>
<dependency>
<groupId>org.apache.poi</groupId>
<artifactId>poi-ooxml</artifactId>
<version>4.1.0</version>
</dependency>
在项目中使用
解决办法: 去掉XSSFCell.CELL_TYPE_ 只保留后面的具体类型
private static String getCellVal(Cell cell) { String val = ""; DateFormat fmt = new SimpleDateFormat("yyyy-MM-dd"); DecimalFormat df = new DecimalFormat("0.0000"); switch (cell.getCellType()) { case NUMERIC: if (DateUtil.isCellDateFormatted(cell)) { val = fmt.format(cell.getDateCellValue()); // 日期型 } else { val = df.format(cell.getNumericCellValue()); // 数字型 val = val.replaceAll("0+?$", "").replaceAll("[.]$", ""); } break; case STRING: val = cell.getStringCellValue(); break; case BOOLEAN: val = String.valueOf(cell.getBooleanCellValue()); break; case BLANK: val = cell.getStringCellValue(); break; case ERROR: val = ""; break; default: val = cell.getRichStringCellValue() == null ? null : cell.getRichStringCellValue().toString(); } return val; }