公共部分

HttpServletResponse

  1. // 需要处理response
  2. HttpServletResponse response;
  3. response.reset();
  4. response.setCharacterEncoding("UTF-8");
  5. response.setContentType("application/x-download");
  6. response.setHeader("Content-Disposition", "attachment; filename=" + new String(fileName.getBytes("UTF-8"), "GBK") + ".xlsx");

写入对象:SendTaskListDataBo

  1. public class SendTaskListDataBo extends BaseRowModel implements Serializable {
  2. /** value为表头,index为列号 */
  3. @ExcelProperty(value = "发放主任务ID" ,index = 0)
  4. private Long mainTaskId;
  5. @ColumnWidth(20)// 列宽度
  6. @ExcelProperty(value = "发放主任务名称" ,index = 1)
  7. private String mainTaskName;
  8. }

通过对象写入方式

  1. // 需要写入的数据
  2. List<SendTaskListDataBo> sendTaskListDataBos;
  3. // 写入到excel中,.sheet定义sheet名称
  4. EasyExcel.write(response.getOutputStream(), SendTaskListDataBo.class)
  5. .sheet("发放任务列表").doWrite(sendTaskListDataBos);

通过模板填充方式

  1. // 模板名称,文件位置:resources/templates/excel
  2. String templateFileName = "templates" + File.separator + "excel" + File.separator + "export_send_task_template.xlsx";
  3. // 写入excel,springboot 使用new ClassPathResource();
  4. ExcelWriter excelWriter = EasyExcel.write(response.getOutputStream()).withTemplate
  5. (new ClassPathResource(templateFileName).getInputStream()).build();
  6. WriteSheet writeSheet = EasyExcel.writerSheet().build();
  7. // 单个对象填充 {name}
  8. excelWriter.fill(sendTaskListDataBo, writeSheet);
  9. // 填充集合 {.name}
  10. excelWriter.fill(subTaskDataBos, writeSheet);
  11. excelWriter.finish();

模板文件excel

EasyExcel写文件的更多相关文章

  1. 分享一个CQRS/ES架构中基于写文件的EventStore的设计思路

    最近打算用C#实现一个基于文件的EventStore. 什么是EventStore 关于什么是EventStore,如果还不清楚的朋友可以去了解下CQRS/Event Sourcing这种架构,我博客 ...

  2. Node.js写文件的三种方法

    Node.js写文件的三种方式: 1.通过管道流写文件 采用管道传输二进制流,可以实现自动管理流,可写流不必当心可读流流的过快而崩溃,适合大小文件传输(推荐) var readStream = fs. ...

  3. iOS持续写文件到本地

    NSString *tempSavePath = [NSString stringWithFormat:@"%@/Documents",kDocumentPath]; NSFile ...

  4. PHP写文件函数

    /** * 写文件函数 * * @param string $filename 文件名 * @param string $text 要写入的文本字符串 * @param string $openmod ...

  5. node基础07:写文件

    1.writeFile //server.js var http = require("http"); var writefile = require("./writef ...

  6. java写文件

                                  randomAccessFile.close();              }                  e.printStack ...

  7. python 写文件,utf-8问题

    写文件报数据. 同样的编码. 含中文字段的输出文件 编码为utf-8 无中文的却是asc import codecstxt = u”qwer”file=codecs.open(“test”,”w”,” ...

  8. Java基础之写文件——将素数写入文件中(PrimesToFile)

    控制台程序,计算素数.创建文件路径.写文件. import static java.lang.Math.ceil; import static java.lang.Math.sqrt; import ...

  9. IAR MSP430如何生成烧写文件

    IAR生成430烧写方法有2种, 第一种是:将工程的debug模式切换成release模式,看图片操作.    那个.d43文件就是仿真调试模式的文件. 这里的test.txt文件就是烧写文件了,不要 ...

随机推荐

  1. Linux后台开发工具箱-葵花宝典

    Linux后台开发工具箱-葵花宝典 一见 2016/11/4 目录 目录 1 1. 前言 4 2. 脚本类工具 4 2.1. 双引号和单引号 4 2.2. 取脚本完整文件路径 5 2.3. 环境变量和 ...

  2. select函数及fd_set介绍

    1. select函数 1. 用途 在编程的过程中,经常会遇到许多阻塞的函数,好像read和网络编程时使用的recv, recvfrom函数都是阻塞的函数,当函数不能成功执行的时候,程序就会一直阻塞在 ...

  3. 【Python笔记】1、格式化输出(%用法和format用法)

    转自:https://www.cnblogs.com/fat39/p/7159881.html 一.格式化输出1.整数的输出%o —— oct 八进制%d —— dec 十进制%x —— hex 十六 ...

  4. NOI2019 Day1游记

    Day1挂了,没什么好说的... 开场T1想到70分暴力就走人了,后来发现可以写到85...(听说有人写dfs过了95?233333) T2刚了2个多小时,得到每次只在中间填最大值的结论后不会区间DP ...

  5. ES6基础-变量的解构赋值

    作者 | Jeskson 来源 | 达达前端小酒馆 解构赋值: 数组的解构赋值,对象的解构赋值,字符串的解构赋值,数值与布尔值的解构赋值,函数参数的解构赋值. 开发环境准备: 编辑器,VS Code, ...

  6. ModuleNotFoundError: No module named 'rest_framework_swagger'

    pip3.6 install django-rest-swagger

  7. SpringCloud:搭建基于Gateway的微服务网关(二)

    0.代码 https://github.com/fengdaizang/OpenAPI 1.引入相关依赖 pom文件如下: <?xml version="1.0" encod ...

  8. phpstudy(小皮面板)和phpstudy2018 配置php的区别

    phpstudy(小皮面板)和phpstudy2018 配置php的区别 一.总结 一句话总结: phpstudy(小皮面板) 和 phpstudy2018 只是引入的php的位置不同,但是核心代码还 ...

  9. 【转】干货篇:手机绕过BL锁9008模式强刷

    <ignore_js_op> 高通QPST线刷其实就是利用高通芯片自带的9008端口,将手机系统内的所有分区的镜像文件,直接刷写手机.这个刷机方式比REC卡刷和fastboot线刷,更底层 ...

  10. Python80个练手项目列表

    原文地址:https://www.shiyanlou.com/questions/102676/?utm_source=baidu&utm_medium=cpc&utm_campaig ...