POI操作Excel时偶尔会出现Cannot get a text value from a numeric cell的异常错误。

异常原因:Excel数据Cell有不同的类型,当我们试图从一个数字类型的Cell读取出一个字符串并写入数据库时,就会出现Cannot get a text value from a numeric cell的异常错误。

此异常常见于类似如下代码中:row.getCell(0).getStringCellValue();

解决办法:先设置Cell的类型,然后就可以把纯数字作为String类型读进来了:

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

相关文章:

  • 2022-12-23
  • 2021-09-08
  • 2018-11-08
  • 2022-02-09
  • 2022-01-06
  • 2021-12-17
  • 2021-07-07
  • 2021-12-16
猜你喜欢
  • 2021-12-31
  • 2021-04-19
  • 2022-12-23
  • 2021-09-29
  • 2021-10-26
  • 2021-08-01
相关资源
相似解决方案