zoukankan      html  css  js  c++  java
  • Java导入excel

    需要先倒入POI的jar
    <dependency>
    <groupId>org.apache.poi</groupId>
    <artifactId>poi-ooxml</artifactId>
    <version>3.8</version>
    </dependency>


    public String exportCharge(MultipartHttpServletRequest request) {
    try {
    //得到上传的文件
    MultipartFile fileFile = request.getFile("file");
    //转换成输入流
    InputStream in = fileFile.getInputStream();
    XSSFWorkbook readWb = new XSSFWorkbook(in);
    //遍历该表格中所有的工作表,i表示工作表的数量 getNumberOfSheets表示工作表的总数

    XSSFSheet sheet = readWb.getSheetAt(0);
    //循环行Row
    for (int rowNum = 1; rowNum <= sheet.getLastRowNum(); rowNum++) {
    System.out.println("当前插入第"+rowNum);
    XSSFRow hssfRow = sheet.getRow(rowNum);
    AllPhone allPhone=new AllPhone();
    if (hssfRow != null) {
    for (int colNum = 0; colNum < hssfRow.getPhysicalNumberOfCells(); colNum++) {
    String tmp = hssfRow.getCell(colNum).toString();
    if (colNum == 0) {
    int begin = tmp.indexOf(".");
    } else if (colNum == 1) {
    allPhone.setStage(tmp);
    }else if (colNum == 2) {

    }else if (colNum == 3) {
    allPhone.setCardtype(tmp);
    }else if (colNum == 4) {


    }else if (colNum == 5) {
    if(StringUtil.isNotEmpty(tmp)){
    allPhone.setPostcode(tmp);
    }
    }
    }
    }
    }

    } catch (Exception e) {
    e.printStackTrace();
    }
    return "ok";
    }


  • 相关阅读:
    Hessain 方法重载
    mac 类似Xshell
    idea & datagrip 注册码
    mac 安装mysql 修改密码
    securecrt 的安装
    datagrip的使用
    mac 安装oracle
    mac 安装mysql
    destoon 会员整合Ucenter/Discuz!/PHPWind教程
    destoon 深度整合discuz x2 UC 之免邮箱二次验证
  • 原文地址:https://www.cnblogs.com/foreverstudy/p/11321234.html
Copyright © 2011-2022 走看看