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

EasyExcel动态实现表头以及数据封装

EasyExcel动态实现表头以及数据封装

实现方法

  public void exportSelfRanking(HttpServletResponse response, ButtonStatisticsParam buttonStatisticsParam) throws IOException {//表头参数List<List<String>> titleList = queryButtonExportTitle();//数据List<List<String>> dataList = queryButtonExportData(buttonStatisticsParam, titleList);//导出response.setContentType("application/vnd.openxmlformats-officedocument.spreadsheetml.sheet");response.setCharacterEncoding("utf-8");// 这里URLEncoder.encode可以防止中文乱码String fileName = URLEncoder.encode("使用情况数据"+DateUtil.format(new Date(),"yyyyMMddHHmmssSSS"), "UTF-8").replaceAll("\\+", "%20");response.setHeader("Content-disposition", "attachment;filename*=utf-8''" + fileName + ".xlsx");EasyExcel.write(response.getOutputStream()).head(titleList).registerWriteHandler(new SimpleColumnWidthStyleStrategy(25)).sheet("功能意向使用情况").doWrite(dataList);}

注:buttonStatisticsParam为导出的检索条件,response为请求头参数
List<List> titleList 为封装的动态表头参数, List<List> dataList 为动态封装的数据参数,registerWriteHandler(new SimpleColumnWidthStyleStrategy(25)) 为设置表格参数,head(titleList) 为存放表头参数


http://www.mrgr.cn/news/8329.html

相关文章:

  • 前端——盒子模型
  • 信创海光x86服务器,定义、特点及应用详解
  • Flink内存调优
  • 【python】OpenCV—Single Human Pose Estimation
  • 数据结构总结
  • Spring的bean的生命周期
  • macOS安装搭建python环境
  • 自然语言处理系列四十二》新词发现与短语提取》新词发现》代码实战
  • redis 过期监听:高效管理数据生命周期
  • ffmpeg6.1集成ffmpeg-gl-transition滤镜
  • 在.NET开发中使用 Excel 的最佳方式之一:MiniExcel
  • leetcode53:最大子数组和
  • Nodejs中使用FFmpeg
  • LLM agentic模式之规划能力(planning)
  • K8S系列——(二)、K8S部署RocketMQ集群
  • Flutter ListView 实现不同样式 item
  • print输出不换行 、制表符、while循环制作九九乘法表 复习奥
  • 遍历时修改列表导致错误或意外行为
  • Tita的OKR :产品经理的OKR
  • 云手机解决了TikTok哪些账号运营难题?