Excel异常Cannot get a text value from a numeric cell

POI操作Excel时数据Cell有不同的类型,当我们试图从一个数字类型的Cell读取出一个字符串并写入数据库时,就会出现Cannot get a text value from a numeric cell的异常错误,解决办法就是先设置Cell的类型,然后就可以把纯数字作为String类型读进来了:

     if(row.getCell(7)!=null){
          row.getCell(7).setCellType(Cell.CELL_TYPE_STRING);
          stuUser.setPhone(row.getCell(7).getStringCellValue());
     }

猜你喜欢

转载自pengzhaocheng16.iteye.com/blog/1835433