码迷,mamicode.com
首页 > Web开发 > 详细

Apache-POI 简单应用

时间:2016-09-11 18:59:15      阅读:191      评论:0      收藏:0      [点我收藏+]

标签:

测试的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);
  }
}

 

Apache-POI 简单应用

标签:

原文地址:http://www.cnblogs.com/loveflycforever/p/5862338.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!