通过POI读取Excel文件时出现了如下的问题:
java.lang.IllegalStateException: Cannot get a text value from a numeric cell
at org.apache.poi.hssf.usermodel.HSSFCell.typeMismatch(HSSFCell.java:648)
at org.apache.poi.hssf.usermodel.HSSFCell.getRichStringCellValue(HSSFCell.java:725)
at org.apache.poi.hssf.usermodel.HSSFCell.getStringCellValue(HSSFCell.java:708)
at com.moku.business.util.ExcelWrite.excelRedad01(ExcelWrite.java:39)
原因是Excel数据Cell有不同的类型,当一个数字类型的Cell读取出一个字符串并写入数据库时,就会出现Cannot get a text value from a numeric cell的异常错误。按照如下设置便可解决问题:
if (cell2 != null){
cell2.setCellType(Cell.CELL_TYPE_STRING);
if (StringUtils.isNotBlank(cell2.getStringCellValue())){
datas.add(cell2.getStringCellValue());
}
}
参考文章
Cannot get a text value from a numeric cell
最新推荐文章于 2022-11-01 16:12:30 发布