导入 @param url @return @throws Exception
(String url)
| 24 | * @throws Exception |
| 25 | */ |
| 26 | public static List<List<String>> poiImport(String url) throws Exception { |
| 27 | List<List<String>> list = new ArrayList<>(); |
| 28 | // 创建Excel 读取文件内容 |
| 29 | HSSFWorkbook workbook = new HSSFWorkbook(FileUtils.openInputStream(new File(url))); |
| 30 | /** |
| 31 | * 第一种方式读取Sheet页 |
| 32 | */ |
| 33 | // HSSFSheet sheet = workbook.getSheet("Sheet0"); |
| 34 | /** |
| 35 | * 第二种方式读取Sheet页 |
| 36 | */ |
| 37 | HSSFSheet sheet = workbook.getSheetAt(0);//获取工作表 |
| 38 | for (int i = 0; i < sheet.getLastRowNum()+1; i++) { |
| 39 | HSSFRow row = sheet.getRow(i);//获取行 |
| 40 | List<String> rowlist = new ArrayList<>();//行数据 |
| 41 | for (int j = 0; j < row.getLastCellNum(); j++) { |
| 42 | HSSFCell cell = row.getCell(j); |
| 43 | cell.setCellType(Cell.CELL_TYPE_STRING); |
| 44 | String value = cell.getStringCellValue(); |
| 45 | rowlist.add(value);//行中数据添加到行中 |
| 46 | } |
| 47 | list.add(rowlist);//将行数据添加到list中 |
| 48 | } |
| 49 | return list; |
| 50 | } |
| 51 | |
| 52 | |
| 53 |