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