zoukankan      html  css  js  c++  java
  • 读取表格上的数据

    //读取excel表格中的数据,path代表excel路径
      public void readExecl(String path) {
        try {
          //读取的时候可以使用流,也可以直接使用文件名
          XSSFWorkbook xwb = new XSSFWorkbook(path);
          //循环工作表sheet
          for (int numSheet = 0; numSheet < xwb.getNumberOfSheets(); numSheet++) {
            XSSFSheet xSheet = xwb.getSheetAt(numSheet);
            if (xSheet == null) {
              continue;
            }
            //循环行row
            for (int numRow = 0; numRow <= xSheet.getLastRowNum(); numRow++) {
              XSSFRow xRow = xSheet.getRow(numRow);
              if (xRow == null) {
                continue;
              }
              //循环列cell
              for (int numCell = 0; numCell <= xRow.getLastCellNum(); numCell++) {
                XSSFCell xCell = xRow.getCell(numCell);
                if (xCell == null) {
                  continue;
                }
                //输出值
                System.out.println("excel表格中取出的数据" + getValue(xCell));
              }
            }
    
          }
    
        } catch (IOException e) {
          e.printStackTrace();
        }
      }
    
      /**
       * 取出每列的值
       *
       * @param xCell 列
       * @return
       */
      private String getValue(XSSFCell xCell) {
        if (xCell.getCellType() == XSSFCell.CELL_TYPE_BOOLEAN) {
          return String.valueOf(xCell.getBooleanCellValue());
        } else if (xCell.getCellType() == XSSFCell.CELL_TYPE_NUMERIC) {
          return String.valueOf(xCell.getNumericCellValue());
        } else {
          return String.valueOf(xCell.getStringCellValue());
        }
      }

     引自

  • 相关阅读:
    Idea中提交SVN或git时,忽略某些文件不提交
    SVN(subversion )服务端和客户端的下载安装使用
    layui官方文档
    使用IntelliJ IDEA配置Tomcat
    IntelliJ IDEA 配置JDK
    设置 IntelliJ IDEA 主题
    mybatis+mysql批量插入和批量更新
    session.资料
    MyEclipse2014.Maven自动更新
    Office.资料
  • 原文地址:https://www.cnblogs.com/minxiaofei/p/10071179.html
Copyright © 2011-2022 走看看