From 958bce2fe7602699814b36ac5a1c243ec9047e50 Mon Sep 17 00:00:00 2001 From: gaoming Date: Wed, 16 Oct 2019 15:00:58 +0800 Subject: [PATCH] 新增过滤隐藏行 --- build.gradle | 2 +- src/main/java/com/taover/util/UtilExcel.java | 107 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++---------------- 2 files changed, 92 insertions(+), 17 deletions(-) diff --git a/build.gradle b/build.gradle index 54ae377..37888b4 100644 --- a/build.gradle +++ b/build.gradle @@ -54,7 +54,7 @@ uploadArchives { authentication(userName: NEXUS_USERNAME, password: NEXUS_PASSWORD) } pom.project { - version '1.1.18' + version '1.1.19' artifactId ARTIFACT_Id groupId GROUP_ID packaging TYPE diff --git a/src/main/java/com/taover/util/UtilExcel.java b/src/main/java/com/taover/util/UtilExcel.java index f02b640..a1260ec 100644 --- a/src/main/java/com/taover/util/UtilExcel.java +++ b/src/main/java/com/taover/util/UtilExcel.java @@ -238,6 +238,22 @@ public class UtilExcel { } /** + * 读取 + * @param filepath + * @return + * @throws Exception + */ + public static List> readExcelExcludeHideLine(String filepath) throws Exception{ + File file = new File(filepath); + List> result = new ArrayList>(); + if(!file.exists()){ + return result; + } + Workbook wb = UtilExcel.getWorkbook(filepath, true); + return readExcelBySheetIndexExcludeHideLine(filepath, wb.getActiveSheetIndex()); + } + + /** * 读取excel表--所有工作表 * @param path */ @@ -313,29 +329,88 @@ public class UtilExcel { return result; } - public static void main(String args[]){ - String filepath = "C:\\Users\\root\\Desktop\\千丁-6.27.xlsx"; - List> data = null; - try { - data = UtilExcel.readExcel(filepath); - } catch (Exception e) { - // TODO Auto-generated catch block - e.printStackTrace(); + public static List> readExcelBySheetIndexExcludeHideLine(String filepath, int sheetIndex) throws Exception{ + File file = new File(filepath); + List> result = new ArrayList>(); + if(!file.exists()){ + return result; } - List styleList = new ArrayList(); - for(int i=0; i UtilExcel.maxExcelRowNum){ + end = UtilExcel.maxExcelRowNum; + } + for(int i=start; i dataRow = new ArrayList(); + int lastCellNum = row.getLastCellNum(); + if(lastCellNum > UtilExcel.maxExcelColumnNum){ + lastCellNum = UtilExcel.maxExcelColumnNum; + } + for(int j=0; j> data = null; try { - UtilExcel.saveExcel("测试", data, "D:\\12345.xlsx", styleList); + data = UtilExcel.readExcel(filepath); + System.out.println(data.size()); + System.out.println(UtilExcel.readExcelExcludeHideLine(filepath).size()); } catch (Exception e) { // TODO Auto-generated catch block e.printStackTrace(); } +// List styleList = new ArrayList(); +// for(int i=0; i