zoukankan      html  css  js  c++  java
  • Apache-POI 简单应用

    测试的Excel文件为四列的普通表格

    jar包:poi-3.15-beta2.jar(Office2003xls文件)、poi-ooxml-3.15-beta2.jar(Office2007xlsx文件)

    File file=new File("D:\testEXC.xlsx");
    if(!file.exists()) {
      throw new FileNotFoundException();
    }
    FileInputStream fis = new FileInputStream(file);
                
    @SuppressWarnings("resource")
    XSSFWorkbook xssfWorkbook = new XSSFWorkbook(fis);
                
    int sheetNum = xssfWorkbook.getNumberOfSheets();
    for(int i = 0;i<sheetNum;i++) {
      Sheet sheet = xssfWorkbook.getSheetAt(i);
                    
      int lastRow = sheet.getLastRowNum();
      if(lastRow <= 0) {
        continue;
      }
                    
      Row row = null;
      String name = "";
      String title = "";
      String content = "";
      String email = "";
                    
      for(int rowNum = 1;rowNum <= lastRow;rowNum++) {
        row = sheet.getRow(rowNum);
        if(row == null) {
          continue;
        }
                        
        name = getCellValue(row.getCell(0));
        title = getCellValue(row.getCell(1));
        content = getCellValue(row.getCell(2));
        email = getCellValue(row.getCell(3));
                        
        System.out.println(name+" / "+title+" / "+content+" / "+email);
      }
    }
    
  • 相关阅读:
    xpath获取a标签下文本
    Python学习笔记Day26
    DNS原理
    命令实战解析
    linux系统ext文件系统知识
    磁盘分区重点知识
    机械磁盘读写磁盘数据的原理
    linux用户管理
    linux命令讲解
    linux系统定时任务
  • 原文地址:https://www.cnblogs.com/loveflycforever/p/5862338.html
Copyright © 2011-2022 走看看