//实体类
@Getter
@Setter
@ToString
@Accessors
@ContentRowHeight(20)
@HeadRowHeight(50)
@ColumnWidth(25)
public class xxxVO implements Serializable {
@ExcelProperty(value = "xxx名称")
private String xxx;
...
}
//controller导出
@PostMapping("/billExport")
public void export(@RequestBody @Validated xxxDTO dto,
HttpServletResponse response)throws Exception{
ResponseVO<List<xxxVO>> vo = consumer.export(dto);
//设置导出为excel表
response.setContentType("application/vnd.ms-excel");
response.setCharacterEncoding("utf-8");
// 防止中文乱码
String fileName = URLEncoder.encode("账单信息", "UTF-8");
response.setHeader("Content-disposition", "attachment;filename=" + fileName + ".xlsx");
EasyExcel.write(response.getOutputStream(), xxxVO.class)
.sheet("账单信息")
.doWrite(vo.getData());
}
EasyExcel演示
于 2022-08-02 09:57:06 首次发布