首页 > 代码库 > Apache-POI 简单应用
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); }}
Apache-POI 简单应用
声明:以上内容来自用户投稿及互联网公开渠道收集整理发布,本网站不拥有所有权,未作人工编辑处理,也不承担相关法律责任,若内容有误或涉及侵权可进行投诉: 投诉/举报 工作人员会在5个工作日内联系你,一经查实,本站将立刻删除涉嫌侵权内容。