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

     引自

  • 相关阅读:
    OC中类的初始化
    iOS UITabBar简单使用
    iOS UIScrollView初体验
    iOS第一个Demo
    Xcode编写第一个iOS Demo(OC)及遇到的坑记录
    OC协议
    诚实的力量。Paul Graham (Y Combinator 创始人)关于诚实的评论。
    php5.4window下连接mssql
    mysql 游标嵌套循环实例
    关于支付宝接口文档的链接
  • 原文地址:https://www.cnblogs.com/minxiaofei/p/10071179.html
Copyright © 2011-2022 走看看