zoukankan      html  css  js  c++  java
  • Excel导入异常Cannot get a text value from a numeric cell解决及poi导入时注意事项

    POI操作Excel时偶尔会出现Cannot get a text value from a numeric cell的异常错误。

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

    此异常常见于类似如下代码中:row.getCell(0).getStringCellValue();

    解决办法:先设置Cell的类型,然后就可以把纯数字作为String类型读进来了:

    if(row.getCell(0)!=null){
              row.getCell(0).setCellType(Cell.CELL_TYPE_STRING);
              stuUser.setPhone(row.getCell(0).getStringCellValue());
         }

    !!!!!poi导入时所得到的行号即getLastRowNum()所得到的行号是总行数 - 1 ,getLastCellNum()即总列数正常,获取行数及列数都是从0开始,

  • 相关阅读:
    Lesson 61-62 Are Relatives Important to You?
    Lesson 59-60 Househusband
    Lesson 57-58 Cosmetic Surgery
    Lesson 55-56 TV Commercials
    Blash
    高维宇宙
    巴卡尔
    完美标号
    小A点菜(luogu 1164)简单DP
    聪明的质监员(qc)
  • 原文地址:https://www.cnblogs.com/dashazia/p/11394870.html
Copyright © 2011-2022 走看看