码迷,mamicode.com
首页 > 其他好文 > 详细

使用poi读取excel文件 Cannot get a text value from a numeric cell

时间:2019-01-18 13:31:00      阅读:214      评论:0      收藏:0      [点我收藏+]

标签:cal   creat   str   lstat   .com   ring   getc   mis   name   

我这样转换得到一个excel文本域的值

Cell cell = row.getCell(c);

cell.setCellType(Cell.CELL_TYPE_STRING);

String parkName = cell.getStringCellValue();

某些时候,读取 excel 文件会出现如下错误

 java.lang.IllegalStateException: Cannot get a text value from a numeric cell
    at org.apache.poi.hssf.usermodel.HSSFCell.typeMismatch(HSSFCell.java:640)

在这里找到了解决方案

stackoverflow

对我的原代码进行更改

 DataFormatter formatter = new DataFormatter(); //creating formatter using the default locale
 Cell cell = row.getCell(c);
 String parkName = formatter.formatCellValue(cell); //Returns the formatted value of a cell as a String regardless of the cell type.

使用poi读取excel文件 Cannot get a text value from a numeric cell

标签:cal   creat   str   lstat   .com   ring   getc   mis   name   

原文地址:https://www.cnblogs.com/daleyzou/p/poi-exception.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!