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

相关文章:

  • 2022-02-09
  • 2021-09-19
  • 2021-08-01
  • 2021-09-29
  • 2021-10-26
  • 2021-12-17
  • 2021-07-21
猜你喜欢
  • 2021-04-19
  • 2021-09-08
  • 2022-12-23
  • 2021-12-31
  • 2021-12-23
  • 2022-12-23
  • 2021-12-16
相关资源
相似解决方案