<dependency>
<groupId>com.alibaba</groupId>
<artifactId>easyexcel</artifactId>
<version>3.2.1</version>
</dependency>
@Data
public class SysRankUserRespVO {
@ExcelProperty(value = "姓名", index = 0)
private String userName;
@ExcelProperty(value = "职级", index = 1)
private String rankName;
@ExcelProperty(value = "员工号", index = 2)
private String empNo;
@ExcelProperty(value = "职级获取时间", index = 3)
private String getTime;
}
@PostMapping(value = "/rank-user-export")
public HttpResult<Void> rankUserExport(HttpServletResponse response, @RequestBody SysRankReqVO reqVO) throws Exception {
List<SysRankUserRespVO> list = surSysRankService.rankUserQuery(reqVO.getId(), 1, 100);
response.setContentType("application/vnd.ms-excel");
response.setCharacterEncoding("utf-8");
String fileName = URLEncoder.encode("用户职级列表导出" +TimeUtils.getCurrentTime(),"UTF-8");
response.setHeader("Content-disposition", "attachment;filename=" + fileName + ".xlsx");
response.setHeader("Access-Control-Expose-Headers", "Content-Disposition");
// 浏览器下载
EasyExcel.write(response.getOutputStream(), SysRankUserRespVO.class)
// 文件类型
.excelType(ExcelTypeEnum.XLSX)
// 是否自动关闭流
.autoCloseStream(Boolean.TRUE)
// 列宽
.registerWriteHandler(new SimpleColumnWidthStyleStrategy(20))
.sheet("用户职级")
.doWrite(list);
return new HttpResultUtil<Void>().setState(HttpMsg.SUCCESS);
}
https://blog.csdn.net/m0_46300599/article/details/138075274
https://blog.csdn.net/qq_57732418/article/details/136944211
标签:index,String,easyExcel,ExcelProperty,导出,value,private,response From: https://www.cnblogs.com/lovedaodao/p/18361257