Browse Source

* 根据文件流解析,由抛出异常改为,默认识别为csv

pull/3168/head
Jiaju Zhuang 2 years ago
parent
commit
67d00c1951
  1. 8
      easyexcel-core/src/main/java/com/alibaba/excel/support/ExcelTypeEnum.java
  2. 9
      easyexcel-core/src/main/java/com/alibaba/excel/util/ClassUtils.java
  3. 1
      easyexcel-support/pom.xml
  4. 5
      easyexcel-test/pom.xml
  5. 4
      update.md

8
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) {

9
easyexcel-core/src/main/java/com/alibaba/excel/util/ClassUtils.java

@ -431,13 +431,12 @@ public class ClassUtils {
}
}
private static Map<Integer, FieldWrapper> buildSortedAllFieldMap(Map<Integer, List<FieldWrapper>> orderFieldMap,
Map<Integer, FieldWrapper> indexFieldMap) {
private static Map<Integer, FieldWrapper> buildSortedAllFieldMap(Map<Integer, List<FieldWrapper>> orderFieldMap, Map<Integer, FieldWrapper> indexFieldMap) {
Map<Integer, FieldWrapper> sortedAllFieldMap = MapUtils.newHashMapWithExpectedSize(
orderFieldMap.size() + indexFieldMap.size());
Map<Integer, FieldWrapper> sortedAllFieldMap = new HashMap<>(
(orderFieldMap.size() + indexFieldMap.size()) * 4 / 3 + 1);
Map<Integer, FieldWrapper> tempIndexFieldMap = MapUtils.newLinkedHashMapWithExpectedSize(indexFieldMap.size());
Map<Integer, FieldWrapper> tempIndexFieldMap = new HashMap<>(indexFieldMap);
int index = 0;
for (List<FieldWrapper> fieldList : orderFieldMap.values()) {
for (FieldWrapper field : fieldList) {

1
easyexcel-support/pom.xml

@ -21,6 +21,7 @@
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-core</artifactId>
<version>5.3.27</version>
<exclusions>
<exclusion>
<groupId>org.springframework</groupId>

5
easyexcel-test/pom.xml

@ -40,6 +40,11 @@
<artifactId>spring-boot-starter-test</artifactId>
<version>2.7.11</version>
</dependency>
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<version>4.13.2</version>
</dependency>
<!-- logback -->
<dependency>

4
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

Loading…
Cancel
Save