Skip to content

Commit

Permalink
* 根据文件流解析,由抛出异常改为,默认识别为csv
Browse files Browse the repository at this point in the history
  • Loading branch information
zhuangjiaju committed May 4, 2023
1 parent 0a4241f commit 67d00c1
Show file tree
Hide file tree
Showing 5 changed files with 17 additions and 10 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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
*/
Expand Down Expand Up @@ -96,13 +98,11 @@ private static ExcelTypeEnum recognitionExcelType(InputStream inputStream) throw
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) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -431,13 +431,12 @@ private static void resortField(WriteHolder writeHolder, FieldCache fieldCache)
}
}

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) {
Expand Down
1 change: 1 addition & 0 deletions easyexcel-support/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-core</artifactId>
<version>5.3.27</version>
<exclusions>
<exclusion>
<groupId>org.springframework</groupId>
Expand Down
5 changes: 5 additions & 0 deletions easyexcel-test/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -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>
Expand Down
4 changes: 3 additions & 1 deletion update.md
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down

0 comments on commit 67d00c1

Please sign in to comment.