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());
        }
      }

     引自

  • 相关阅读:
    Leetcode Word Pattern
    Leetcode Strobogrammatic Number
    Leetcode Meeting Rooms
    Leetcode Pascal's Triangle II
    Leetcode Pascal's Triangle
    Leetcode Majority Element II
    Leetcode Majority Element
    牛客多校第六场 B Shorten IPv6 Address 模拟
    牛客多校第六场 A Garbage 模拟/签到
    排列数,康托展开及其线段树优化
  • 原文地址:https://www.cnblogs.com/minxiaofei/p/10071179.html
Copyright © 2011-2022 走看看