异常描述
这个错误的原因是因为要操作的excel表里面的不能将数字类型的单元个用String来接收
解决办法
自己定义一个判断的方法来判断表中出现的各种数据类型,以及出现空和空字符串的情况,方法如下所示
public Object getValue(Cell cell){
if (cell==null || cell.getCellType()== CellType.BLANK){
return null;
}
Object value = null;
switch (cell.getCellType()){
case NUMERIC:
if (DateUtil.isCellDateFormatted(cell)){
value = cell.getDateCellValue();
}else {
value = new BigDecimal(cell.getNumericCellValue());
}
break;
case BOOLEAN:
value = cell.getBooleanCellValue();
break;
case STRING:
value = cell.getStringCellValue();
break;
default:
value = null;
}
return value;
}
接收数据时就要调用这个方法来接收
System.out.print(getValue(cell) + "\t");