Skip to content

Commit 69b583c

Browse files
Merge pull request #231 from shiyindaxiaojie/feature
update
2 parents 9037391 + f72c8e0 commit 69b583c

16 files changed

Lines changed: 659 additions & 2 deletions

File tree

eden-components/eden-dependencies/pom.xml

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -90,6 +90,7 @@
9090
<jakarta.el.version>3.0.4</jakarta.el.version>
9191
<classmate.version>1.5.1</classmate.version>
9292
<easyexcel.version>3.2.0</easyexcel.version>
93+
<fastexcel.version>1.1.0</fastexcel.version>
9394
<poi.version>4.1.1</poi.version>
9495
<dom4j.version>2.1.3</dom4j.version>
9596
<batik.version>1.12</batik.version>
@@ -1134,6 +1135,12 @@
11341135
<version>${jakarta.el.version}</version>
11351136
</dependency>
11361137
<!-- EasyExcel -->
1138+
<dependency>
1139+
<groupId>cn.idev.excel</groupId>
1140+
<artifactId>fastexcel</artifactId>
1141+
<version>${fastexcel.version}</version>
1142+
</dependency>
1143+
<!-- FastExcel -->
11371144
<dependency>
11381145
<groupId>com.alibaba</groupId>
11391146
<artifactId>easyexcel</artifactId>

eden-components/eden-solutions/eden-common-excel/pom.xml

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -58,11 +58,20 @@
5858
<optional>true</optional>
5959
</dependency>
6060

61+
<!-- EasyExcel -->
62+
<dependency>
63+
<groupId>cn.idev.excel</groupId>
64+
<artifactId>fastexcel</artifactId>
65+
</dependency>
66+
6167
<!-- EasyExcel -->
6268
<dependency>
6369
<groupId>com.alibaba</groupId>
6470
<artifactId>easyexcel</artifactId>
71+
<optional>true</optional>
6572
</dependency>
73+
74+
<!-- Other -->
6675
<dependency>
6776
<groupId>org.springframework</groupId>
6877
<artifactId>spring-web</artifactId>
Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
/*
2+
* Copyright 2012-2019 the original author or authors.
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License");
5+
* you may not use this file except in compliance with the License.
6+
* You may obtain a copy of the License at
7+
*
8+
* https://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS,
12+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
* See the License for the specific language governing permissions and
14+
* limitations under the License.
15+
*/
16+
17+
package org.ylzl.eden.common.excel;
18+
19+
import java.lang.annotation.*;
20+
21+
/**
22+
* Excel 属性项
23+
*
24+
* @author <a href="mailto:shiyindaxiaojie@gmail.com">gyl</a>
25+
* @since 2.4.x
26+
*/
27+
@Target(ElementType.FIELD)
28+
@Retention(RetentionPolicy.RUNTIME)
29+
@Inherited
30+
public @interface ExcelProperty {
31+
32+
String[] value() default {""};
33+
34+
int index() default -1;
35+
36+
int order() default Integer.MAX_VALUE;
37+
}
Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
/*
2+
* Copyright 2012-2019 the original author or authors.
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License");
5+
* you may not use this file except in compliance with the License.
6+
* You may obtain a copy of the License at
7+
*
8+
* https://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS,
12+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
* See the License for the specific language governing permissions and
14+
* limitations under the License.
15+
*/
16+
17+
package org.ylzl.eden.common.excel.converter;
18+
19+
/**
20+
* TODO
21+
*
22+
* @author <a href="mailto:shiyindaxiaojie@gmail.com">gyl</a>
23+
* @since 2.4.x
24+
*/
25+
public interface Converter<T> {
26+
27+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,98 @@
1+
/*
2+
* Copyright 2012-2019 the original author or authors.
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License");
5+
* you may not use this file except in compliance with the License.
6+
* You may obtain a copy of the License at
7+
*
8+
* https://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS,
12+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
* See the License for the specific language governing permissions and
14+
* limitations under the License.
15+
*/
16+
17+
package org.ylzl.eden.common.excel.integration.fastexcel;
18+
19+
import cn.idev.excel.context.AnalysisContext;
20+
import cn.idev.excel.event.AnalysisEventListener;
21+
import cn.idev.excel.read.builder.ExcelReaderBuilder;
22+
import lombok.Data;
23+
import lombok.RequiredArgsConstructor;
24+
import org.ylzl.eden.common.excel.ExcelReader;
25+
import org.ylzl.eden.common.excel.reader.ExcelReadListener;
26+
27+
import java.io.File;
28+
import java.io.InputStream;
29+
30+
/**
31+
* EasyExcel 读取 Excel
32+
*
33+
* @author <a href="mailto:shiyindaxiaojie@gmail.com">gyl</a>
34+
* @since 2.4.x
35+
*/
36+
@RequiredArgsConstructor
37+
@Data
38+
public class FastExcelReader implements ExcelReader {
39+
40+
private final ExcelReaderBuilder excelReaderBuilder;
41+
42+
private boolean readExcelLine = false;
43+
44+
/**
45+
* 读取 Excel
46+
*
47+
* @param inputStream 输入流
48+
* @param head 标题映射
49+
* @param excelReadListener 读取监听器
50+
*/
51+
@Override
52+
public void read(InputStream inputStream, Class<?> head, ExcelReadListener<?> excelReadListener) {
53+
excelReaderBuilder.file(inputStream)
54+
.head(head)
55+
.autoCloseStream(true)
56+
.registerReadListener(new AnalysisEventListener<Object>() {
57+
58+
@Override
59+
public void invoke(Object data, AnalysisContext context) {
60+
excelReadListener.read(data);
61+
}
62+
63+
@Override
64+
public void doAfterAllAnalysed(AnalysisContext context) {
65+
excelReadListener.finish();
66+
}
67+
})
68+
.sheet()
69+
.doRead();
70+
}
71+
72+
/**
73+
* 读取 Excel
74+
*
75+
* @param file 文件
76+
* @param head 标题映射
77+
* @param excelReadListener 读取监听器
78+
*/
79+
@Override
80+
public void read(File file, Class<?> head, ExcelReadListener<?> excelReadListener) {
81+
excelReaderBuilder.file(file)
82+
.head(head)
83+
.registerReadListener(new AnalysisEventListener<Object>() {
84+
85+
@Override
86+
public void invoke(Object data, AnalysisContext context) {
87+
excelReadListener.read(data);
88+
}
89+
90+
@Override
91+
public void doAfterAllAnalysed(AnalysisContext context) {
92+
excelReadListener.finish();
93+
}
94+
})
95+
.sheet()
96+
.doRead();
97+
}
98+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,49 @@
1+
/*
2+
* Copyright 2012-2019 the original author or authors.
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License");
5+
* you may not use this file except in compliance with the License.
6+
* You may obtain a copy of the License at
7+
*
8+
* https://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS,
12+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
* See the License for the specific language governing permissions and
14+
* limitations under the License.
15+
*/
16+
17+
package org.ylzl.eden.common.excel.integration.fastexcel;
18+
19+
import cn.idev.excel.FastExcel;
20+
import org.ylzl.eden.common.excel.ExcelReader;
21+
import org.ylzl.eden.common.excel.builder.AbstractExcelReaderBuilder;
22+
import org.ylzl.eden.common.excel.builder.ExcelReaderBuilder;
23+
import org.ylzl.eden.common.excel.integration.fastexcel.converter.LocalDateConverter;
24+
import org.ylzl.eden.common.excel.integration.fastexcel.converter.LocalDateTimeConverter;
25+
26+
/**
27+
* EasyExcel 读取 Excel
28+
*
29+
* @author <a href="mailto:shiyindaxiaojie@gmail.com">gyl</a>
30+
* @since 2.4.x
31+
*/
32+
public class FastExcelReaderBuilder extends AbstractExcelReaderBuilder implements ExcelReaderBuilder {
33+
34+
/**
35+
* 构建 Excel 读取器
36+
*
37+
* @param headRowNumber 标题行数
38+
* @param ignoreEmptyRow 忽略空行
39+
* @return Excel 读取器实例
40+
*/
41+
@Override
42+
public ExcelReader build(int headRowNumber, boolean ignoreEmptyRow) {
43+
return new FastExcelReader(FastExcel.read()
44+
.registerConverter(LocalDateConverter.INSTANCE)
45+
.registerConverter(LocalDateTimeConverter.INSTANCE)
46+
.headRowNumber(headRowNumber)
47+
.ignoreEmptyRow(ignoreEmptyRow));
48+
}
49+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,69 @@
1+
package org.ylzl.eden.common.excel.integration.fastexcel;
2+
3+
import cn.idev.excel.write.builder.ExcelWriterBuilder;
4+
import lombok.Data;
5+
import lombok.RequiredArgsConstructor;
6+
import org.ylzl.eden.common.excel.ExcelWriter;
7+
8+
import java.io.File;
9+
import java.io.OutputStream;
10+
import java.util.List;
11+
12+
/**
13+
* EasyExcel 写入 Excel
14+
*
15+
* @author <a href="mailto:shiyindaxiaojie@gmail.com">gyl</a>
16+
* @since 2.4.13
17+
*/
18+
@RequiredArgsConstructor
19+
@Data
20+
public class FastExcelWriter implements ExcelWriter {
21+
22+
private final ExcelWriterBuilder excelWriterBuilder;
23+
24+
/**
25+
* 写入 Excel
26+
*
27+
* @param outputStream 输出流
28+
* @param data 填充数据
29+
* @param head 标题
30+
*/
31+
@Override
32+
public void write(OutputStream outputStream, List<Object> data, Class<?> head) {
33+
excelWriterBuilder.file(outputStream)
34+
.autoCloseStream(true)
35+
.head(head)
36+
.sheet()
37+
.doWrite(data);
38+
}
39+
40+
/**
41+
* 写入 Excel
42+
*
43+
* @param file 文件
44+
* @param data 填充数据
45+
* @param head 标题
46+
*/
47+
@Override
48+
public void write(File file, List<Object> data, Class<?> head) {
49+
excelWriterBuilder.file(file)
50+
.autoCloseStream(true)
51+
.head(head)
52+
.sheet()
53+
.doWrite(data);
54+
}
55+
56+
private cn.idev.excel.ExcelWriter build(OutputStream outputStream) {
57+
return excelWriterBuilder.file(outputStream)
58+
.autoCloseStream(true)
59+
.build();
60+
}
61+
62+
private boolean isManySheets(Object data) {
63+
if (data instanceof List) {
64+
List<?> objList = (List<?>) data;
65+
return !objList.isEmpty() && objList.get(0) instanceof List;
66+
}
67+
return false;
68+
}
69+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,67 @@
1+
/*
2+
* Copyright 2012-2019 the original author or authors.
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License");
5+
* you may not use this file except in compliance with the License.
6+
* You may obtain a copy of the License at
7+
*
8+
* https://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS,
12+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
* See the License for the specific language governing permissions and
14+
* limitations under the License.
15+
*/
16+
17+
package org.ylzl.eden.common.excel.integration.fastexcel;
18+
19+
import cn.idev.excel.FastExcel;
20+
import cn.idev.excel.support.ExcelTypeEnum;
21+
import org.ylzl.eden.common.excel.ExcelType;
22+
import org.ylzl.eden.common.excel.ExcelWriter;
23+
import org.ylzl.eden.common.excel.builder.AbstractExcelWriterBuilder;
24+
import org.ylzl.eden.common.excel.builder.ExcelWriterBuilder;
25+
import org.ylzl.eden.common.excel.integration.fastexcel.converter.LocalDateConverter;
26+
import org.ylzl.eden.common.excel.integration.fastexcel.converter.LocalDateTimeConverter;
27+
28+
/**
29+
* EasyExcel 写入 Excel
30+
*
31+
* @author <a href="mailto:shiyindaxiaojie@gmail.com">gyl</a>
32+
* @since 2.4.x
33+
*/
34+
public class FastExcelWriterBuilder extends AbstractExcelWriterBuilder implements ExcelWriterBuilder {
35+
36+
/**
37+
* 构建 Excel 写入器
38+
*
39+
* @param excelType 文件类型
40+
* @param inMemory 是否在内存操作
41+
* @return Excel 写入器实例
42+
*/
43+
@Override
44+
public ExcelWriter build(ExcelType excelType, boolean inMemory) {
45+
return new FastExcelWriter(FastExcel.write()
46+
.registerConverter(LocalDateConverter.INSTANCE)
47+
.registerConverter(LocalDateTimeConverter.INSTANCE)
48+
.excelType(this.valueOf(excelType))
49+
.inMemory(inMemory));
50+
}
51+
52+
/**
53+
* 枚举转换
54+
*
55+
* @param excelType 文件类型
56+
* @return EasyExcel 枚举
57+
*/
58+
private ExcelTypeEnum valueOf(ExcelType excelType) {
59+
switch (excelType) {
60+
case CSV:
61+
return ExcelTypeEnum.CSV;
62+
case XLS:
63+
return ExcelTypeEnum.XLS;
64+
}
65+
return ExcelTypeEnum.XLSX;
66+
}
67+
}

0 commit comments

Comments
 (0)