使用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