Java中通过POI读取Excel 2003 - 2007的xls,xlsx格式
程序员文章站
2022-06-03 17:44:24
...
@Test public void testRead() throws IOException, InvalidFormatException { // String fileName = "e:/workbook.xls"; String fileName = "e:/workbook.xlsx"; Workbook wb = WorkbookFactory.create(new FileInputStream(fileName)); int sheetNum = wb.getNumberOfSheets(); for (int i = 0; i < sheetNum; i++) { Sheet childSheet = wb.getSheetAt(i); int rowNum = childSheet.getLastRowNum(); for (int j = 0; j < rowNum; j++) { Row row = childSheet.getRow(j); int cellNum = row.getLastCellNum(); for (int k = 0; k < cellNum; k++) { System.out.print(row.getCell(k).toString() + " "); } System.out.println(); } } }
上一篇: 奢侈品牌业绩增长齐现疲态 电子政务