当前位置: 首页 > news >正文

easyexcel 动态列导出

1. 引入easyexcel

        <dependency><groupId>com.alibaba</groupId><artifactId>easyexcel</artifactId><version>3.2.1</version></dependency>

2.导出write

public void export(HttpServletResponse response) {try {String fileName = "测试导出动态列" + System.currentTimeMillis();Set<String> includeColumnFiledNames = new HashSet<>();includeColumnFiledNames.add("title");includeColumnFiledNames.add("openId");List<Category> categoryList = getAllCategory();List<CategoryExport> categoryExports = BeanUtil.copyToList(categoryList, CategoryExport.class);response.setContentType("application/vnd.ms-excel");// 设置文本内省response.setCharacterEncoding("utf-8");// 设置字符编码response.setHeader("Content-disposition", "attachment;filename=" + URLEncoder.encode(fileName, "UTF-8") + ".xlsx"); // 设置响应头ExcelWriterBuilder write = EasyExcel.write(response.getOutputStream(), CategoryExport.class);if (includeColumnFiledNames.size() > 0) {write.includeColumnFieldNames(includeColumnFiledNames);}write.sheet("模板").doWrite(categoryExports); //用io流来写入数据} catch (IOException e) {e.printStackTrace();}}

3.导出类

@Data
public class CategoryExport implements Serializable {private static final long serialVersionUID = 1L;private Long id;@ExcelProperty("openId")private String openId;@ExcelProperty("priority")private Integer priority;@ExcelProperty("标题")private String title;
}

http://www.lryc.cn/news/331961.html

相关文章:

  • flink源码编译-job提交
  • Mysql密码修改问题
  • 建独立站,对FP商家有什么好处?
  • 使用Postman进行websocket接口测试
  • Android音视频开发 - MediaMetadataRetriever 相关
  • 注解(Annotation)
  • 蓝桥杯:七步诗 ← bfs
  • Vue 如何快速上手
  • Vue3:组件间通信-provide和inject实现祖先组件与后代组件间直接通信
  • 微信小程序——小程序和页面生命周期详解
  • android studio中添加module依赖
  • 【.NET全栈】.NET全栈学习路线
  • 代码随想录阅读笔记-二叉树【二叉搜索树中的搜索】
  • 1、初识drf
  • 速盾:cdn高防御服务器租用有哪些好处
  • 【跟小嘉学 Linux 系统架构与开发】四、文件和目录的权限
  • ubuntu18.04图形界面卡死,鼠标键盘失灵, 通过MAC共享网络给Ubuntu解决!
  • ESG认证(ESG=环境、社会和治理 Environmental, Social, and Governance)
  • Cesium Viewer 类学习
  • 第十四届省赛大学B组(C/C++)子串简写
  • 深入浅出 -- 系统架构之微服务架构
  • YoloV8改进策略:下采样改进|自研下采样模块(独家改进)|疯狂涨点|附结构图
  • Python从0到100(十):Python集合介绍及运用
  • 实用技巧:如何取消app的截屏禁用
  • 【氮化镓】GaN SP-HEMT的栅极可靠性
  • Linux基础和进阶用法
  • Linux运维-SHELL编程之正则表达式与流编辑处理器
  • openGauss学习笔记-256 openGauss性能调优-使用Plan Hint进行调优-优化器GUC参数的Hint
  • flex:1的作用是什么?
  • Mysql安装(命令方式安装)