Exception in thread "main" java.lang.IllegalStateException: Cannot get a text value from a numeric c

版权声明:https://blog.csdn.net/Burgess_Lee https://blog.csdn.net/Burgess_Lee/article/details/83619536

java从excel中用poi工具进行解析时候,项目启动报错。

错误场景如下:

//部分代码
returnStr = c.getRichStringCellValue().getString();

然后在执行之后提示

Exception in thread "main" java.lang.IllegalStateException: Cannot get a text value from a numeric c

经过晚上查看解释如下:

Excel数据Cell有不同的类型,当我们试图从一个数字类型的Cell读取出一个字符串需要设置类型.


解决:

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

c.setCellType(Cell.CELL_TYPE_STRING);
returnStr = c.getRichStringCellValue().getString();

问题解决。

猜你喜欢

转载自blog.csdn.net/Burgess_Lee/article/details/83619536