From 67d00c195171c8e42fd44f4807454c61c2368c19 Mon Sep 17 00:00:00 2001 From: Jiaju Zhuang Date: Thu, 4 May 2023 20:30:44 +0800 Subject: [PATCH] =?UTF-8?q?*=20=E6=A0=B9=E6=8D=AE=E6=96=87=E4=BB=B6?= =?UTF-8?q?=E6=B5=81=E8=A7=A3=E6=9E=90=EF=BC=8C=E7=94=B1=E6=8A=9B=E5=87=BA?= =?UTF-8?q?=E5=BC=82=E5=B8=B8=E6=94=B9=E4=B8=BA=EF=BC=8C=E9=BB=98=E8=AE=A4?= =?UTF-8?q?=E8=AF=86=E5=88=AB=E4=B8=BAcsv?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../java/com/alibaba/excel/support/ExcelTypeEnum.java | 8 ++++---- .../src/main/java/com/alibaba/excel/util/ClassUtils.java | 9 ++++----- easyexcel-support/pom.xml | 1 + easyexcel-test/pom.xml | 5 +++++ update.md | 4 +++- 5 files changed, 17 insertions(+), 10 deletions(-) diff --git a/easyexcel-core/src/main/java/com/alibaba/excel/support/ExcelTypeEnum.java b/easyexcel-core/src/main/java/com/alibaba/excel/support/ExcelTypeEnum.java index 09ab04ec..e78bf94c 100644 --- a/easyexcel-core/src/main/java/com/alibaba/excel/support/ExcelTypeEnum.java +++ b/easyexcel-core/src/main/java/com/alibaba/excel/support/ExcelTypeEnum.java @@ -23,10 +23,12 @@ public enum ExcelTypeEnum { * csv */ CSV(".csv", new byte[] {-27, -89, -109, -27}), + /** * xls */ XLS(".xls", new byte[] {-48, -49, 17, -32, -95, -79, 26, -31}), + /** * xlsx */ @@ -96,13 +98,11 @@ public enum ExcelTypeEnum { byte[] data = IOUtils.peekFirstNBytes(inputStream, MAX_PATTERN_LENGTH); if (findMagic(XLSX.magic, data)) { return XLSX; - } else if (findMagic(CSV.magic, data)) { - return CSV; } else if (findMagic(XLS.magic, data)) { return XLS; } - throw new ExcelCommonException( - "Convert excel format exception.You can try specifying the 'excelType' yourself"); + // csv has no fixed prefix, if the format is not specified, it defaults to csv + return CSV; } private static boolean findMagic(byte[] expected, byte[] actual) { diff --git a/easyexcel-core/src/main/java/com/alibaba/excel/util/ClassUtils.java b/easyexcel-core/src/main/java/com/alibaba/excel/util/ClassUtils.java index c5062176..df9d3683 100644 --- a/easyexcel-core/src/main/java/com/alibaba/excel/util/ClassUtils.java +++ b/easyexcel-core/src/main/java/com/alibaba/excel/util/ClassUtils.java @@ -431,13 +431,12 @@ public class ClassUtils { } } - private static Map buildSortedAllFieldMap(Map> orderFieldMap, - Map indexFieldMap) { + private static Map buildSortedAllFieldMap(Map> orderFieldMap, Map indexFieldMap) { - Map sortedAllFieldMap = MapUtils.newHashMapWithExpectedSize( - orderFieldMap.size() + indexFieldMap.size()); + Map sortedAllFieldMap = new HashMap<>( + (orderFieldMap.size() + indexFieldMap.size()) * 4 / 3 + 1); - Map tempIndexFieldMap = MapUtils.newLinkedHashMapWithExpectedSize(indexFieldMap.size()); + Map tempIndexFieldMap = new HashMap<>(indexFieldMap); int index = 0; for (List fieldList : orderFieldMap.values()) { for (FieldWrapper field : fieldList) { diff --git a/easyexcel-support/pom.xml b/easyexcel-support/pom.xml index 23613040..20e7c937 100644 --- a/easyexcel-support/pom.xml +++ b/easyexcel-support/pom.xml @@ -21,6 +21,7 @@ org.springframework spring-core + 5.3.27 org.springframework diff --git a/easyexcel-test/pom.xml b/easyexcel-test/pom.xml index 1a39d325..926ad2c4 100644 --- a/easyexcel-test/pom.xml +++ b/easyexcel-test/pom.xml @@ -40,6 +40,11 @@ spring-boot-starter-test 2.7.11 + + junit + junit + 4.13.2 + diff --git a/update.md b/update.md index 66c04037..52d78383 100644 --- a/update.md +++ b/update.md @@ -7,9 +7,11 @@ * 在`easyexcel-parent` 包中移除测试包的`dependencyManagement` * 删除`org.apache.poi.hssf.usermodel.PoiUtils.java`, 使用反射获取 [Issue #2804](https://github.com/alibaba/easyexcel/issues/2804) -* 默认对象反射缓存改成`ThreadLocal`,并支持设置反射缓存类型 [Issue #2792](https://github.com/alibaba/easyexcel/issues/2792) +* 默认对象反射缓存改成`ThreadLocal` + ,并支持设置反射缓存类型 [Issue #2792](https://github.com/alibaba/easyexcel/issues/2792) * 支持根据`includeColumnIndexes`和`includeColumnFieldNames` 排序 [Issue #2697](https://github.com/alibaba/easyexcel/issues/2697) +* 根据文件流解析,由抛出异常改为,默认识别为csv # 3.2.1