Skip to content

Commit c843434

Browse files
jiang4yuCharles7c
authored andcommitted
feat(file/poi): 新增 continew-starter-file-poi 模块(添加 ExcelImport 与 ExcelExport 注解)
1.将EasyExcel升级为FastExcel 2.新增 continew-starter-file-poi 模块(添加 ExcelImport 与 ExcelExport 注解,https://zyqok.blog.csdn.net/article/details/121994504
1 parent ad29893 commit c843434

File tree

12 files changed

+1235
-27
lines changed

12 files changed

+1235
-27
lines changed

continew-starter-dependencies/pom.xml

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@
3131
<aj-captcha.version>1.4.0</aj-captcha.version>
3232
<easy-captcha.version>1.6.2</easy-captcha.version>
3333
<nashorn.version>15.6</nashorn.version>
34-
<easy-excel.version>3.3.4</easy-excel.version>
34+
<fastexcel.version>1.2.0</fastexcel.version>
3535
<x-file-storage.version>2.2.1</x-file-storage.version>
3636
<aws-s3.version>1.12.783</aws-s3.version>
3737
<s3.version>2.31.35</s3.version>
@@ -228,9 +228,9 @@
228228

229229
<!-- Easy Excel(基于 Java 的、快速、简洁、解决大文件内存溢出的 Excel 处理工具) -->
230230
<dependency>
231-
<groupId>com.alibaba</groupId>
232-
<artifactId>easyexcel</artifactId>
233-
<version>${easy-excel.version}</version>
231+
<groupId>cn.idev.excel</groupId>
232+
<artifactId>fastexcel</artifactId>
233+
<version>${fastexcel.version}</version>
234234
</dependency>
235235

236236
<!-- X File Storage(一行代码将文件存储到本地、FTP、SFTP、WebDAV、阿里云 OSS、华为云 OBS...等其它兼容 S3 协议的存储平台) -->

continew-starter-file/continew-starter-file-excel/pom.xml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,8 +18,8 @@
1818
<dependencies>
1919
<!-- Easy Excel(基于 Java 的、快速、简洁、解决大文件内存溢出的 Excel 处理工具) -->
2020
<dependency>
21-
<groupId>com.alibaba</groupId>
22-
<artifactId>easyexcel</artifactId>
21+
<groupId>cn.idev.excel</groupId>
22+
<artifactId>fastexcel</artifactId>
2323
</dependency>
2424
</dependencies>
2525
</project>

continew-starter-file/continew-starter-file-excel/src/main/java/top/continew/starter/file/excel/converter/ExcelBaseEnumConverter.java

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -16,12 +16,12 @@
1616

1717
package top.continew.starter.file.excel.converter;
1818

19-
import com.alibaba.excel.converters.Converter;
20-
import com.alibaba.excel.enums.CellDataTypeEnum;
21-
import com.alibaba.excel.metadata.GlobalConfiguration;
22-
import com.alibaba.excel.metadata.data.ReadCellData;
23-
import com.alibaba.excel.metadata.data.WriteCellData;
24-
import com.alibaba.excel.metadata.property.ExcelContentProperty;
19+
import cn.idev.excel.converters.Converter;
20+
import cn.idev.excel.enums.CellDataTypeEnum;
21+
import cn.idev.excel.metadata.GlobalConfiguration;
22+
import cn.idev.excel.metadata.data.ReadCellData;
23+
import cn.idev.excel.metadata.data.WriteCellData;
24+
import cn.idev.excel.metadata.property.ExcelContentProperty;
2525
import top.continew.starter.core.constant.StringConstants;
2626
import top.continew.starter.core.enums.BaseEnum;
2727

continew-starter-file/continew-starter-file-excel/src/main/java/top/continew/starter/file/excel/converter/ExcelBigNumberConverter.java

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -18,12 +18,12 @@
1818

1919
import cn.hutool.core.convert.Convert;
2020
import cn.hutool.core.util.NumberUtil;
21-
import com.alibaba.excel.converters.Converter;
22-
import com.alibaba.excel.enums.CellDataTypeEnum;
23-
import com.alibaba.excel.metadata.GlobalConfiguration;
24-
import com.alibaba.excel.metadata.data.ReadCellData;
25-
import com.alibaba.excel.metadata.data.WriteCellData;
26-
import com.alibaba.excel.metadata.property.ExcelContentProperty;
21+
import cn.idev.excel.converters.Converter;
22+
import cn.idev.excel.enums.CellDataTypeEnum;
23+
import cn.idev.excel.metadata.GlobalConfiguration;
24+
import cn.idev.excel.metadata.data.ReadCellData;
25+
import cn.idev.excel.metadata.data.WriteCellData;
26+
import cn.idev.excel.metadata.property.ExcelContentProperty;
2727

2828
/**
2929
* Easy Excel 大数值转换器

continew-starter-file/continew-starter-file-excel/src/main/java/top/continew/starter/file/excel/converter/ExcelListConverter.java

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -18,12 +18,12 @@
1818

1919
import cn.hutool.core.collection.CollUtil;
2020
import cn.hutool.core.text.CharSequenceUtil;
21-
import com.alibaba.excel.converters.Converter;
22-
import com.alibaba.excel.enums.CellDataTypeEnum;
23-
import com.alibaba.excel.metadata.GlobalConfiguration;
24-
import com.alibaba.excel.metadata.data.ReadCellData;
25-
import com.alibaba.excel.metadata.data.WriteCellData;
26-
import com.alibaba.excel.metadata.property.ExcelContentProperty;
21+
import cn.idev.excel.converters.Converter;
22+
import cn.idev.excel.enums.CellDataTypeEnum;
23+
import cn.idev.excel.metadata.GlobalConfiguration;
24+
import cn.idev.excel.metadata.data.ReadCellData;
25+
import cn.idev.excel.metadata.data.WriteCellData;
26+
import cn.idev.excel.metadata.property.ExcelContentProperty;
2727
import org.springframework.stereotype.Component;
2828
import top.continew.starter.core.constant.StringConstants;
2929

continew-starter-file/continew-starter-file-excel/src/main/java/top/continew/starter/file/excel/util/ExcelUtils.java

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -19,8 +19,8 @@
1919
import cn.hutool.core.date.DatePattern;
2020
import cn.hutool.core.date.DateUtil;
2121
import cn.hutool.core.util.URLUtil;
22-
import com.alibaba.excel.EasyExcelFactory;
23-
import com.alibaba.excel.write.style.column.LongestMatchColumnWidthStyleStrategy;
22+
import cn.idev.excel.FastExcelFactory;
23+
import cn.idev.excel.write.style.column.LongestMatchColumnWidthStyleStrategy;
2424
import jakarta.servlet.http.HttpServletResponse;
2525
import org.slf4j.Logger;
2626
import org.slf4j.LoggerFactory;
@@ -78,7 +78,7 @@ public static <T> void export(List<T> list,
7878
.format(new Date(), DatePattern.PURE_DATETIME_PATTERN)));
7979
response.setHeader("Content-disposition", "attachment;filename=" + exportFileName);
8080
response.setContentType("application/vnd.openxmlformats-officedocument.spreadsheetml.sheet;charset=utf-8");
81-
EasyExcelFactory.write(response.getOutputStream(), clazz)
81+
FastExcelFactory.write(response.getOutputStream(), clazz)
8282
.autoCloseStream(false)
8383
// 自动适配宽度
8484
.registerWriteHandler(new LongestMatchColumnWidthStyleStrategy())
Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
2+
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
3+
<modelVersion>4.0.0</modelVersion>
4+
<parent>
5+
<groupId>top.continew</groupId>
6+
<artifactId>continew-starter-file</artifactId>
7+
<version>${revision}</version>
8+
</parent>
9+
10+
<artifactId>continew-starter-file-poi</artifactId>
11+
<description>ContiNew Starter 文件处理模块 - POI</description>
12+
13+
<dependencies>
14+
<!-- 文件上传 -->
15+
<dependency>
16+
<groupId>org.apache.httpcomponents.client5</groupId>
17+
<artifactId>httpclient5</artifactId>
18+
</dependency>
19+
<!-- JSON -->
20+
<dependency>
21+
<groupId>com.alibaba</groupId>
22+
<artifactId>fastjson</artifactId>
23+
</dependency>
24+
<dependency>
25+
<groupId>org.springframework</groupId>
26+
<artifactId>spring-webmvc</artifactId>
27+
</dependency>
28+
<dependency>
29+
<groupId>jakarta.servlet</groupId>
30+
<artifactId>jakarta.servlet-api</artifactId>
31+
</dependency>
32+
<!-- POI -->
33+
<dependency>
34+
<groupId>org.apache.poi</groupId>
35+
<artifactId>poi-ooxml</artifactId>
36+
<version>5.4.1</version>
37+
</dependency>
38+
</dependencies>
39+
</project>
Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
package top.continew.starter.file.poi.annotation;
2+
3+
import java.lang.annotation.ElementType;
4+
import java.lang.annotation.Retention;
5+
import java.lang.annotation.RetentionPolicy;
6+
import java.lang.annotation.Target;
7+
8+
/**
9+
* @author jiang4yu
10+
*/
11+
@Target(ElementType.FIELD)
12+
@Retention(RetentionPolicy.RUNTIME)
13+
public @interface ExcelExport {
14+
15+
/**
16+
* 字段名称
17+
*/
18+
String value();
19+
20+
/**
21+
* 导出排序先后: 数字越小越靠前(默认按Java类字段顺序导出)
22+
*/
23+
int sort() default 0;
24+
25+
/**
26+
* 导出映射,格式如:0-未知;1-男;2-女
27+
*/
28+
String kv() default "";
29+
30+
/**
31+
* 导出模板示例值(有值的话,直接取该值,不做映射)
32+
*/
33+
String example() default "";
34+
35+
}
Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
package top.continew.starter.file.poi.annotation;
2+
3+
import java.lang.annotation.ElementType;
4+
import java.lang.annotation.Retention;
5+
import java.lang.annotation.RetentionPolicy;
6+
import java.lang.annotation.Target;
7+
8+
/**
9+
* @author jiang4yu
10+
*/
11+
@Target(ElementType.FIELD)
12+
@Retention(RetentionPolicy.RUNTIME)
13+
public @interface ExcelImport {
14+
15+
/**
16+
* 字段名称
17+
*/
18+
String value();
19+
20+
/**
21+
* 导出映射,格式如:0-未知;1-男;2-女
22+
*/
23+
String kv() default "";
24+
25+
/**
26+
* 是否为必填字段(默认为非必填)
27+
*/
28+
boolean required() default false;
29+
30+
/**
31+
* 最大长度(默认255)
32+
*/
33+
int maxLength() default 255;
34+
35+
/**
36+
* 导入唯一性验证(多个字段则取联合验证)
37+
*/
38+
boolean unique() default false;
39+
40+
}
Lines changed: 88 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,88 @@
1+
package top.continew.starter.file.poi.model;
2+
3+
import java.util.LinkedHashMap;
4+
5+
/**
6+
* @author jiang4yu
7+
*/
8+
public class ExcelClassField {
9+
10+
/**
11+
* 字段名称
12+
*/
13+
private String fieldName;
14+
15+
/**
16+
* 表头名称
17+
*/
18+
private String name;
19+
20+
/**
21+
* 映射关系
22+
*/
23+
private LinkedHashMap<String, String> kvMap;
24+
25+
/**
26+
* 示例值
27+
*/
28+
private Object example;
29+
30+
/**
31+
* 排序
32+
*/
33+
private int sort;
34+
35+
/**
36+
* 是否为注解字段:0-否,1-是
37+
*/
38+
private int hasAnnotation;
39+
40+
public String getFieldName() {
41+
return fieldName;
42+
}
43+
44+
public void setFieldName(String fieldName) {
45+
this.fieldName = fieldName;
46+
}
47+
48+
public String getName() {
49+
return name;
50+
}
51+
52+
public void setName(String name) {
53+
this.name = name;
54+
}
55+
56+
public LinkedHashMap<String, String> getKvMap() {
57+
return kvMap;
58+
}
59+
60+
public void setKvMap(LinkedHashMap<String, String> kvMap) {
61+
this.kvMap = kvMap;
62+
}
63+
64+
public Object getExample() {
65+
return example;
66+
}
67+
68+
public void setExample(Object example) {
69+
this.example = example;
70+
}
71+
72+
public int getSort() {
73+
return sort;
74+
}
75+
76+
public void setSort(int sort) {
77+
this.sort = sort;
78+
}
79+
80+
public int getHasAnnotation() {
81+
return hasAnnotation;
82+
}
83+
84+
public void setHasAnnotation(int hasAnnotation) {
85+
this.hasAnnotation = hasAnnotation;
86+
}
87+
88+
}

0 commit comments

Comments
 (0)