场景

使用POI实现Excel导入时提示:

Cannot get a text value from a numeric cell

POI实现Excel导入Cannot get a text value from a numeric cellPOI实现Excel导入Cannot get a text value from a numeric cell

解决

Excel数据Cell有不同的数据类型,从一个数字类型的Cell读取出一个字符串并写入数据库时,就会出现Cannot get a text value from a numeric cell的异常错误。

添加此行代码:

row1.getCell(1).setCellType(Cell.CELL_TYPE_STRING);

举例:

 

//获取第一行数据
            Row row1 =sheet.getRow(0);
            if(row1!=null){
                //获取采购订单号
                row1.getCell(1).setCellType(Cell.CELL_TYPE_STRING);
                String purchaseCode =row1.getCell(1).getStringCellValue();
                receiveOrder.setPurchaseCode(purchaseCode);
            }

 

相关文章:

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