栏目分类:
子分类:
返回
名师互学网用户登录
快速导航关闭
当前搜索
当前分类
子分类
实用工具
热门搜索
名师互学网 > IT > 软件开发 > 后端开发 > Java

Cannot get a text value from a numeric cell

Java 更新时间: 发布时间: IT归档 最新发布 模块sitemap 名妆网 法律咨询 聚返吧 英语巴士网 伯小乐 网商动力

Cannot get a text value from a numeric cell

        通过poi来读取excel文件过程中,通过cell.getStringCellValue()方法尝试从一个数字类型的Cell读取出一个字符串时报错。

报错:

Exception in thread "main" java.lang.IllegalStateException: Cannot get a text value from a numeric cell
    at org.apache.poi.xssf.usermodel.XSSFCell.typeMismatch(XSSFCell.java:845)
    at org.apache.poi.xssf.usermodel.XSSFCell.getRichStringCellValue(XSSFCell.java:294)
    at org.apache.poi.xssf.usermodel.XSSFCell.getStringCellValue(XSSFCell.java:246)
    at com.li.demo.utils.Service.upload(Service.java:39)
    at com.li.demo.utils.Service.main(Service.java:20)

解决方法:

 cell存在类型问题,可以在获取数据前先设置好cell的类型,如下:

 

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

转载请注明:文章转载自 www.mshxw.com
本文地址:https://www.mshxw.com/it/693029.html
我们一直用心在做
关于我们 文章归档 网站地图 联系我们

版权所有 (c)2021-2022 MSHXW.COM

ICP备案号:晋ICP备2021003244-6号