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)
This commit is contained in:
jiang4yu
2025-06-10 03:48:26 +00:00
committed by Charles7c
parent ad298930db
commit c843434720
12 changed files with 1235 additions and 27 deletions

View File

@@ -31,7 +31,7 @@
<aj-captcha.version>1.4.0</aj-captcha.version> <aj-captcha.version>1.4.0</aj-captcha.version>
<easy-captcha.version>1.6.2</easy-captcha.version> <easy-captcha.version>1.6.2</easy-captcha.version>
<nashorn.version>15.6</nashorn.version> <nashorn.version>15.6</nashorn.version>
<easy-excel.version>3.3.4</easy-excel.version> <fastexcel.version>1.2.0</fastexcel.version>
<x-file-storage.version>2.2.1</x-file-storage.version> <x-file-storage.version>2.2.1</x-file-storage.version>
<aws-s3.version>1.12.783</aws-s3.version> <aws-s3.version>1.12.783</aws-s3.version>
<s3.version>2.31.35</s3.version> <s3.version>2.31.35</s3.version>
@@ -228,9 +228,9 @@
<!-- Easy Excel基于 Java 的、快速、简洁、解决大文件内存溢出的 Excel 处理工具) --> <!-- Easy Excel基于 Java 的、快速、简洁、解决大文件内存溢出的 Excel 处理工具) -->
<dependency> <dependency>
<groupId>com.alibaba</groupId> <groupId>cn.idev.excel</groupId>
<artifactId>easyexcel</artifactId> <artifactId>fastexcel</artifactId>
<version>${easy-excel.version}</version> <version>${fastexcel.version}</version>
</dependency> </dependency>
<!-- X File Storage一行代码将文件存储到本地、FTP、SFTP、WebDAV、阿里云 OSS、华为云 OBS...等其它兼容 S3 协议的存储平台) --> <!-- X File Storage一行代码将文件存储到本地、FTP、SFTP、WebDAV、阿里云 OSS、华为云 OBS...等其它兼容 S3 协议的存储平台) -->

View File

@@ -18,8 +18,8 @@
<dependencies> <dependencies>
<!-- Easy Excel基于 Java 的、快速、简洁、解决大文件内存溢出的 Excel 处理工具) --> <!-- Easy Excel基于 Java 的、快速、简洁、解决大文件内存溢出的 Excel 处理工具) -->
<dependency> <dependency>
<groupId>com.alibaba</groupId> <groupId>cn.idev.excel</groupId>
<artifactId>easyexcel</artifactId> <artifactId>fastexcel</artifactId>
</dependency> </dependency>
</dependencies> </dependencies>
</project> </project>

View File

@@ -16,12 +16,12 @@
package top.continew.starter.file.excel.converter; package top.continew.starter.file.excel.converter;
import com.alibaba.excel.converters.Converter; import cn.idev.excel.converters.Converter;
import com.alibaba.excel.enums.CellDataTypeEnum; import cn.idev.excel.enums.CellDataTypeEnum;
import com.alibaba.excel.metadata.GlobalConfiguration; import cn.idev.excel.metadata.GlobalConfiguration;
import com.alibaba.excel.metadata.data.ReadCellData; import cn.idev.excel.metadata.data.ReadCellData;
import com.alibaba.excel.metadata.data.WriteCellData; import cn.idev.excel.metadata.data.WriteCellData;
import com.alibaba.excel.metadata.property.ExcelContentProperty; import cn.idev.excel.metadata.property.ExcelContentProperty;
import top.continew.starter.core.constant.StringConstants; import top.continew.starter.core.constant.StringConstants;
import top.continew.starter.core.enums.BaseEnum; import top.continew.starter.core.enums.BaseEnum;

View File

@@ -18,12 +18,12 @@ package top.continew.starter.file.excel.converter;
import cn.hutool.core.convert.Convert; import cn.hutool.core.convert.Convert;
import cn.hutool.core.util.NumberUtil; import cn.hutool.core.util.NumberUtil;
import com.alibaba.excel.converters.Converter; import cn.idev.excel.converters.Converter;
import com.alibaba.excel.enums.CellDataTypeEnum; import cn.idev.excel.enums.CellDataTypeEnum;
import com.alibaba.excel.metadata.GlobalConfiguration; import cn.idev.excel.metadata.GlobalConfiguration;
import com.alibaba.excel.metadata.data.ReadCellData; import cn.idev.excel.metadata.data.ReadCellData;
import com.alibaba.excel.metadata.data.WriteCellData; import cn.idev.excel.metadata.data.WriteCellData;
import com.alibaba.excel.metadata.property.ExcelContentProperty; import cn.idev.excel.metadata.property.ExcelContentProperty;
/** /**
* Easy Excel 大数值转换器 * Easy Excel 大数值转换器

View File

@@ -18,12 +18,12 @@ package top.continew.starter.file.excel.converter;
import cn.hutool.core.collection.CollUtil; import cn.hutool.core.collection.CollUtil;
import cn.hutool.core.text.CharSequenceUtil; import cn.hutool.core.text.CharSequenceUtil;
import com.alibaba.excel.converters.Converter; import cn.idev.excel.converters.Converter;
import com.alibaba.excel.enums.CellDataTypeEnum; import cn.idev.excel.enums.CellDataTypeEnum;
import com.alibaba.excel.metadata.GlobalConfiguration; import cn.idev.excel.metadata.GlobalConfiguration;
import com.alibaba.excel.metadata.data.ReadCellData; import cn.idev.excel.metadata.data.ReadCellData;
import com.alibaba.excel.metadata.data.WriteCellData; import cn.idev.excel.metadata.data.WriteCellData;
import com.alibaba.excel.metadata.property.ExcelContentProperty; import cn.idev.excel.metadata.property.ExcelContentProperty;
import org.springframework.stereotype.Component; import org.springframework.stereotype.Component;
import top.continew.starter.core.constant.StringConstants; import top.continew.starter.core.constant.StringConstants;

View File

@@ -19,8 +19,8 @@ package top.continew.starter.file.excel.util;
import cn.hutool.core.date.DatePattern; import cn.hutool.core.date.DatePattern;
import cn.hutool.core.date.DateUtil; import cn.hutool.core.date.DateUtil;
import cn.hutool.core.util.URLUtil; import cn.hutool.core.util.URLUtil;
import com.alibaba.excel.EasyExcelFactory; import cn.idev.excel.FastExcelFactory;
import com.alibaba.excel.write.style.column.LongestMatchColumnWidthStyleStrategy; import cn.idev.excel.write.style.column.LongestMatchColumnWidthStyleStrategy;
import jakarta.servlet.http.HttpServletResponse; import jakarta.servlet.http.HttpServletResponse;
import org.slf4j.Logger; import org.slf4j.Logger;
import org.slf4j.LoggerFactory; import org.slf4j.LoggerFactory;
@@ -78,7 +78,7 @@ public class ExcelUtils {
.format(new Date(), DatePattern.PURE_DATETIME_PATTERN))); .format(new Date(), DatePattern.PURE_DATETIME_PATTERN)));
response.setHeader("Content-disposition", "attachment;filename=" + exportFileName); response.setHeader("Content-disposition", "attachment;filename=" + exportFileName);
response.setContentType("application/vnd.openxmlformats-officedocument.spreadsheetml.sheet;charset=utf-8"); response.setContentType("application/vnd.openxmlformats-officedocument.spreadsheetml.sheet;charset=utf-8");
EasyExcelFactory.write(response.getOutputStream(), clazz) FastExcelFactory.write(response.getOutputStream(), clazz)
.autoCloseStream(false) .autoCloseStream(false)
// 自动适配宽度 // 自动适配宽度
.registerWriteHandler(new LongestMatchColumnWidthStyleStrategy()) .registerWriteHandler(new LongestMatchColumnWidthStyleStrategy())

View File

@@ -0,0 +1,39 @@
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<parent>
<groupId>top.continew</groupId>
<artifactId>continew-starter-file</artifactId>
<version>${revision}</version>
</parent>
<artifactId>continew-starter-file-poi</artifactId>
<description>ContiNew Starter 文件处理模块 - POI</description>
<dependencies>
<!-- 文件上传 -->
<dependency>
<groupId>org.apache.httpcomponents.client5</groupId>
<artifactId>httpclient5</artifactId>
</dependency>
<!-- JSON -->
<dependency>
<groupId>com.alibaba</groupId>
<artifactId>fastjson</artifactId>
</dependency>
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-webmvc</artifactId>
</dependency>
<dependency>
<groupId>jakarta.servlet</groupId>
<artifactId>jakarta.servlet-api</artifactId>
</dependency>
<!-- POI -->
<dependency>
<groupId>org.apache.poi</groupId>
<artifactId>poi-ooxml</artifactId>
<version>5.4.1</version>
</dependency>
</dependencies>
</project>

View File

@@ -0,0 +1,35 @@
package top.continew.starter.file.poi.annotation;
import java.lang.annotation.ElementType;
import java.lang.annotation.Retention;
import java.lang.annotation.RetentionPolicy;
import java.lang.annotation.Target;
/**
* @author jiang4yu
*/
@Target(ElementType.FIELD)
@Retention(RetentionPolicy.RUNTIME)
public @interface ExcelExport {
/**
* 字段名称
*/
String value();
/**
* 导出排序先后: 数字越小越靠前默认按Java类字段顺序导出
*/
int sort() default 0;
/**
* 导出映射格式如0-未知;1-男;2-女
*/
String kv() default "";
/**
* 导出模板示例值(有值的话,直接取该值,不做映射)
*/
String example() default "";
}

View File

@@ -0,0 +1,40 @@
package top.continew.starter.file.poi.annotation;
import java.lang.annotation.ElementType;
import java.lang.annotation.Retention;
import java.lang.annotation.RetentionPolicy;
import java.lang.annotation.Target;
/**
* @author jiang4yu
*/
@Target(ElementType.FIELD)
@Retention(RetentionPolicy.RUNTIME)
public @interface ExcelImport {
/**
* 字段名称
*/
String value();
/**
* 导出映射格式如0-未知;1-男;2-女
*/
String kv() default "";
/**
* 是否为必填字段(默认为非必填)
*/
boolean required() default false;
/**
* 最大长度默认255
*/
int maxLength() default 255;
/**
* 导入唯一性验证(多个字段则取联合验证)
*/
boolean unique() default false;
}

View File

@@ -0,0 +1,88 @@
package top.continew.starter.file.poi.model;
import java.util.LinkedHashMap;
/**
* @author jiang4yu
*/
public class ExcelClassField {
/**
* 字段名称
*/
private String fieldName;
/**
* 表头名称
*/
private String name;
/**
* 映射关系
*/
private LinkedHashMap<String, String> kvMap;
/**
* 示例值
*/
private Object example;
/**
* 排序
*/
private int sort;
/**
* 是否为注解字段0-否1-是
*/
private int hasAnnotation;
public String getFieldName() {
return fieldName;
}
public void setFieldName(String fieldName) {
this.fieldName = fieldName;
}
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
public LinkedHashMap<String, String> getKvMap() {
return kvMap;
}
public void setKvMap(LinkedHashMap<String, String> kvMap) {
this.kvMap = kvMap;
}
public Object getExample() {
return example;
}
public void setExample(Object example) {
this.example = example;
}
public int getSort() {
return sort;
}
public void setSort(int sort) {
this.sort = sort;
}
public int getHasAnnotation() {
return hasAnnotation;
}
public void setHasAnnotation(int hasAnnotation) {
this.hasAnnotation = hasAnnotation;
}
}

View File

@@ -17,6 +17,7 @@
<modules> <modules>
<module>continew-starter-file-excel</module> <module>continew-starter-file-excel</module>
<module>continew-starter-file-poi</module>
</modules> </modules>
<dependencies> <dependencies>