The error is as follows:
Exception in thread " main " java.lang.IllegalStateException: Cannot get a STRING value from a NUMERIC cell at org.apache.poi.xssf.usermodel.XSSFCell.typeMismatch(XSSFCell.java: 1050 ) at org.apache.poi.xssf.usermodel.XSSFCell.getRichStringCellValue(XSSFCell.java: 404 ) at org.apache.poi.xssf.usermodel.XSSFCell.getRichStringCellValue(XSSFCell.java: 70 ) at com.jawasoft.testDemo.ExcelUtil.readExcel(ExcelUtil.java: 81 ) at com.jawasoft.testDemo.ExcelUtil.readExcelToObj(ExcelUtil.java: 46 ) at com.jawasoft.testDemo.ExcelUtil.main(ExcelUtil.java: 29 )
Reason for error: When reading the cell string, there is data of type number, so it needs to be converted into pure String type, so that no error will be reported.
Error code:
returnStr = cell.getRichStringCellValue().getString();
or the following code
// Get cell data String cellValue = cell.getStringCellValue();
Solution: Set the cell type to String before reading the excel cell data conversion
code show as below:
//set cell type cell.setCellType(CellType.STRING); returnStr = cell.getRichStringCellValue().getString();
Similar Posts:
- How to Solve ReferenceError: internalBinding is not defined
- [Solved] XSSF Read Excel Error: java.lang.IllegalStateException: Cannot get a STRING value from a NUMERIC cell
- [Solved] JAVA:java.lang.ClassNotFoundException: sun.jdbc.odbc.JdbcodbcDrive
- [Solved] java.util.MissingResourceException: Can’t find bundle for base name db, locale zh_CN
- The solution to the java.lang.ClassCastException: [B cannot be cast to java.lang.String error in kettle
- [Solved] Zookeeper reads data error: Exception in thread “main” org.I0Itec.zkclient.exception.ZkMarshallingError…
- [Solved] Exception in thread “main” java.lang.NoSuchMethodError: org.apache.hadoop.security.HadoopKerberosName.setRuleMechanism(Ljava/lang/String;)V
- Only one SparkContext may be running in this JVM
- [Solved] C Programmer Error: double free or corruption (fasttop)
- [Solved] Mybatis Codes Error: java.lang.ClassNotFoundException: Cannot find class: com.mysql.jdbc.Driver