// 公共参数
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
EasyExcel教程:自定义Excel表头与忽略字段
本文介绍如何使用EasyExcel在Java中创建Excel文件,包括设置表头高度、列宽,以及如何通过注解控制哪些属性不导出。还分享了相关技术博客链接,如简化Excel操作的EasyExcel框架介绍。
4万+

被折叠的 条评论
为什么被折叠?



