From a4f5d61287d4ab9e55c1f03ca47b078b5de511cb Mon Sep 17 00:00:00 2001 From: unknown Date: Wed, 1 Jan 2020 15:07:47 +0800 Subject: [PATCH] part utilExcel --- src/main/java/com/taover/util/UtilExcel.java | 104 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++---- 1 file changed, 100 insertions(+), 4 deletions(-) diff --git a/src/main/java/com/taover/util/UtilExcel.java b/src/main/java/com/taover/util/UtilExcel.java index dca5e0c..866bfa2 100644 --- a/src/main/java/com/taover/util/UtilExcel.java +++ b/src/main/java/com/taover/util/UtilExcel.java @@ -11,7 +11,6 @@ import java.util.List; import java.util.Map; import org.apache.poi.hssf.usermodel.HSSFWorkbook; -import org.apache.poi.hssf.util.HSSFColor; import org.apache.poi.ss.usermodel.Cell; import org.apache.poi.ss.usermodel.CellStyle; import org.apache.poi.ss.usermodel.CellType; @@ -25,7 +24,7 @@ public class UtilExcel { private final static String excel2007U =".xlsx"; //2007+ 版本的excel private final static String CSV =".csv"; //csv - private final static int maxExcelRowNum = 5000; + private final static int maxExcelRowNum = 10000; private final static int maxExcelColumnNum = 50; /** @@ -245,6 +244,20 @@ public class UtilExcel { } /** + * 读取excel表--当前激活的工作表 + * @param path + */ + public static List> readExcel(String filepath, int rowLimit) throws Exception{ + File file = new File(filepath); + List> result = new ArrayList>(); + if(!file.exists()){ + return result; + } + Workbook wb = UtilExcel.getWorkbook(filepath, true); + return readExcelBySheetIndex(filepath, wb.getActiveSheetIndex()); + } + + /** * 读取 * @param filepath * @return @@ -297,8 +310,43 @@ public class UtilExcel { int start = sheet.getFirstRowNum(); int end = sheet.getLastRowNum(); if(end > UtilExcel.maxExcelRowNum){ - end = UtilExcel.maxExcelRowNum; + throw new Exception("目前系统只支持读取10000行以内记录,您当前Excel行数过大"); + } + for(int i=start; i dataRow = new ArrayList(); + int lastCellNum = row.getLastCellNum(); + if(lastCellNum > UtilExcel.maxExcelColumnNum){ + lastCellNum = UtilExcel.maxExcelColumnNum; + } + for(int j=0; j> readExcelBySheet(Sheet sheet, int rowLimit) throws Exception{ + List> result = new ArrayList>(); + int start = sheet.getFirstRowNum(); + int end = sheet.getLastRowNum(); + if(end > rowLimit){ + end = rowLimit; } + DecimalFormat df = new DecimalFormat("0"); for(int i=start; i UtilExcel.maxExcelRowNum){ - end = UtilExcel.maxExcelRowNum; + throw new Exception("目前系统只支持读取10000行以内记录,您当前Excel行数过大"); } for(int i=start; i> readExcelBySheetExcludeHideLine(Sheet sheet, int rowLimit) throws Exception{ + List> result = new ArrayList>(); + DecimalFormat df = new DecimalFormat("0"); + int start = sheet.getFirstRowNum(); + int end = sheet.getLastRowNum(); + if(end > rowLimit){ + end = rowLimit; + } + for(int i=start; i dataRow = new ArrayList(); + int lastCellNum = row.getLastCellNum(); + if(lastCellNum > UtilExcel.maxExcelColumnNum){ + lastCellNum = UtilExcel.maxExcelColumnNum; + } + for(int j=0; j