Required jar package:
Baidu Netdisk:
Link: https://pan.baidu.com/s/1nNM40d3r9VhNjtshyIiJGA
Extraction code: fv6r
Step 1: Create entity objects that need to be exported. Add @ExcelObject to the class, the value is the sheet name
Add the @ExcelField annotation to the attribute of the class, and the value value is its corresponding name in the excel table
Step 2: Create an ExcelData object, and pass the object to be printed into ExcelData.
List<TransactionItemEntity> records = (List<TransactionItemEntity>) pageVo.getRecords();
ExcelData<TransactionItemEntity> excelData = new ExcelData<>(TransactionItemEntity.class);
excelData.putData(records);
When instantiating ExcelData, pass in the same generic type as List<T>. The parameter of the constructor is T.class (generic class)
Step 3: Instantiate ExcelFactory and import the ExcelData object. then export the table
ExcelFactory excelFactory = new ExcelFactory("交易记录");
excelFactory.put(excelData);
String filePath = excelFactory.export();
The parameter of the constructor is an endorsement of the file name.
The put() function can pass in multiple ExcelData objects. Used to export multiple excel files with sheets