Commit 21a5319f5be05edc012a5508e5c936dd610bf9f5
1 parent
626d93d1
Exists in
master
.
Showing
2 changed files
with
27 additions
and
3 deletions
Show diff stats
build.gradle
src/main/java/com/taover/util/UtilExcel.java
... | ... | @@ -291,6 +291,29 @@ public class UtilExcel { |
291 | 291 | |
292 | 292 | return result; |
293 | 293 | } |
294 | + | |
295 | + | |
296 | + /** | |
297 | + * 读取excel表--所有工作表 Map封装 | |
298 | + * @param path | |
299 | + */ | |
300 | + public static Map<String,List<List<Object>>> readExcelAllSheetMap(String filepath) throws Exception{ | |
301 | + File file = new File(filepath); | |
302 | + HashMap<String, List<List<Object>>> map = new HashMap<String,List<List<Object>>>(); | |
303 | + if(!file.exists()){ | |
304 | + throw new Exception("Excel["+filepath+"]文件不存在"); | |
305 | + } | |
306 | + Workbook wb = UtilExcel.getWorkbook(filepath, true); | |
307 | + int sheetNumber = wb.getNumberOfSheets(); | |
308 | + | |
309 | + for(int sheetIndex=0; sheetIndex<sheetNumber; ++sheetIndex){ | |
310 | + map.put(sheetIndex+"",(readExcelBySheetIndexExcludeHideLine(filepath, sheetIndex))); | |
311 | + } | |
312 | + | |
313 | + return map; | |
314 | + } | |
315 | + | |
316 | + | |
294 | 317 | |
295 | 318 | /** |
296 | 319 | * 读取excel表--当前激活的工作表 |
... | ... | @@ -421,13 +444,14 @@ public class UtilExcel { |
421 | 444 | |
422 | 445 | public static void main(String args[]){ |
423 | 446 | //String filepath = "C:\\Users\\root\\Desktop\\千丁-6.27.xlsx"; |
424 | - String filepath = "C:\\Users\\EDZ\\Desktop\\qwer.xlsx"; | |
447 | + String filepath = "C:\\Users\\EDZ\\Desktop\\qwer.xls"; | |
425 | 448 | List<List<Object>> data = null; |
449 | + | |
426 | 450 | try { |
427 | 451 | data = UtilExcel.readExcel(filepath); |
428 | 452 | System.out.println(data); |
429 | 453 | System.out.println(data.size()); |
430 | - System.out.println(UtilExcel.readExcelExcludeHideLine(filepath).size()); | |
454 | + System.out.println(UtilExcel.readExcelAllSheetMap(filepath)); | |
431 | 455 | } catch (Exception e) { |
432 | 456 | // TODO Auto-generated catch block |
433 | 457 | e.printStackTrace(); | ... | ... |