// 公共参数
private static final String CONTENT_TYPE = "application/vnd.openxmlformats-officedocument.spreadsheetml.sheet";
private static final String NAME = "file";
private static final String SHEET_NAME = "sheet1";
// 方法主要逻辑
List<PropertyCountPageResp> list = this.selectPropertyExportExcelDataList(req);
String fileName = "事业部数据统计"+ UUIDUtil.getLongUUID() +".xlsx";
ByteArrayOutputStream byteArrayOutputStream = new ByteArrayOutputStream();
EasyExcel.write(byteArrayOutputStream)
.sheet(1,SHEET_NAME)
.head(PropertyCountPageResp.class)//设置表格数据对象
.doWrite(list);
MultipartFile file = new MockMultipartFile(
NAME,
fileName,
CONTENT_TYPE,
byteArrayOutputStream.toByteArray());
1. PropertyCountPageResp 表格数据对象实体。
2. PropertyCountPageResp 中设置表头
PropertyCountPageResp 中:
在类上添加
@HeadRowHeight(20)
@ColumnWidth(30) //表头宽度
@ContentRowHeight(20)
3.
PropertyCountPageResp中:
忽略不导出属性使用注解 @ExcelIgnore
设置列名和顺序 @ExcelProperty(value = "事业部名称", index = 1)
4. 相关博客推荐
5.官网 EasyExcel · 语雀快速、简单避免OOM的java处理Excel工具https://www.yuque.com/easyexcel