The following is an example of README for the open source project excel-spring-boot-starter generated based on the content you provide:
excel-spring-boot-starter is a Spring Boot Starter based on EasyExcel implementation, used to simplify the read and write operations of Excel. EasyExcel is a Java open source project designed to read and write Excel files with the lowest possible memory consumption. EasyExcel allows you to read 75M (460,000 rows, 25 columns) of Excel files in 1 minute with only 64M memory.
The project has been uploaded to the Maven central repository and can be used by simply introducing the following dependencies:
| Version | Supported version |
|---|---|
| 3.3.1 | Adapt to Spring Boot 3.x |
| 1.2.7 | Adapt to Spring Boot 2.x |
Add the following dependencies in pom.xml :
< dependency >
< groupId >com.pig4cloud.excel</ groupId >
< artifactId >excel-spring-boot-starter</ artifactId >
< version >${lastVersion}</ version >
</ dependency > You can receive the uploaded Excel file and parse it into a Java object list by using @RequestExcel annotation in the interface method:
@ PostMapping ( "/upload" )
public void upload ( @ RequestExcel List < DemoData > dataList , BindingResult bindingResult ) {
// JSR 303 校验通用校验获取失败的数据
List < ErrorMessage > errorMessageList = ( List < ErrorMessage >) bindingResult . getTarget ();
} You need to first define the entity class corresponding to the Excel table, and use @ExcelProperty annotation to annotate the index of the Excel column:
@ Data
public class Demo {
@ ExcelProperty ( index = 0 )
private String username ;
@ ExcelProperty ( index = 1 )
private String password ;
}The following figure shows the Excel table corresponding to the above entity class:
You just need to return a List in the controller method and use the @ResponseExcel annotation to export the data to an Excel file:
@ Documented
@ Target ( ElementType . METHOD )
@ Retention ( RetentionPolicy . RUNTIME )
public @interface ResponseExcel {
String name () default "" ;
ExcelTypeEnum suffix () default ExcelTypeEnum . XLSX ;
String password () default "" ;
Sheet [] sheets () default @ Sheet ( sheetName = "sheet1" );
boolean inMemory () default false ;
String template () default "" ;
String [] include () default {};
String [] exclude () default {};
Class <? extends WriteHandler >[] writeHandler () default {};
Class <? extends Converter >[] converter () default {};
Class <? extends HeadGenerator > headGenerator () default HeadGenerator . class ;
}For more detailed instructions, please refer to the document: https://www.yuque.com/pig4cloud/ogf9nv