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


我这样转换得到一个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.


免责声明!

本站转载的文章为个人学习借鉴使用,本站对版权不负任何法律责任。如果侵犯了您的隐私权益,请联系本站邮箱yoyou2525@163.com删除。



 
粤ICP备18138465号  © 2018-2025 CODEPRJ.COM