EasyExcel写文件
公共部分
HttpServletResponse
// 需要处理response
HttpServletResponse response;
response.reset();
response.setCharacterEncoding("UTF-8");
response.setContentType("application/x-download");
response.setHeader("Content-Disposition", "attachment; filename=" + new String(fileName.getBytes("UTF-8"), "GBK") + ".xlsx");
写入对象:SendTaskListDataBo
public class SendTaskListDataBo extends BaseRowModel implements Serializable {
/** value为表头,index为列号 */
@ExcelProperty(value = "发放主任务ID" ,index = 0)
private Long mainTaskId;
@ColumnWidth(20)// 列宽度
@ExcelProperty(value = "发放主任务名称" ,index = 1)
private String mainTaskName;
}
通过对象写入方式
// 需要写入的数据
List<SendTaskListDataBo> sendTaskListDataBos;
// 写入到excel中,.sheet定义sheet名称
EasyExcel.write(response.getOutputStream(), SendTaskListDataBo.class)
.sheet("发放任务列表").doWrite(sendTaskListDataBos);
通过模板填充方式
// 模板名称,文件位置:resources/templates/excel
String templateFileName = "templates" + File.separator + "excel" + File.separator + "export_send_task_template.xlsx";
// 写入excel,springboot 使用new ClassPathResource();
ExcelWriter excelWriter = EasyExcel.write(response.getOutputStream()).withTemplate
(new ClassPathResource(templateFileName).getInputStream()).build();
WriteSheet writeSheet = EasyExcel.writerSheet().build();
// 单个对象填充 {name}
excelWriter.fill(sendTaskListDataBo, writeSheet);
// 填充集合 {.name}
excelWriter.fill(subTaskDataBos, writeSheet);
excelWriter.finish();
模板文件excel
EasyExcel写文件的更多相关文章
- 分享一个CQRS/ES架构中基于写文件的EventStore的设计思路
最近打算用C#实现一个基于文件的EventStore. 什么是EventStore 关于什么是EventStore,如果还不清楚的朋友可以去了解下CQRS/Event Sourcing这种架构,我博客 ...
- Node.js写文件的三种方法
Node.js写文件的三种方式: 1.通过管道流写文件 采用管道传输二进制流,可以实现自动管理流,可写流不必当心可读流流的过快而崩溃,适合大小文件传输(推荐) var readStream = fs. ...
- iOS持续写文件到本地
NSString *tempSavePath = [NSString stringWithFormat:@"%@/Documents",kDocumentPath]; NSFile ...
- PHP写文件函数
/** * 写文件函数 * * @param string $filename 文件名 * @param string $text 要写入的文本字符串 * @param string $openmod ...
- node基础07:写文件
1.writeFile //server.js var http = require("http"); var writefile = require("./writef ...
- java写文件
randomAccessFile.close(); } e.printStack ...
- python 写文件,utf-8问题
写文件报数据. 同样的编码. 含中文字段的输出文件 编码为utf-8 无中文的却是asc import codecstxt = u”qwer”file=codecs.open(“test”,”w”,” ...
- Java基础之写文件——将素数写入文件中(PrimesToFile)
控制台程序,计算素数.创建文件路径.写文件. import static java.lang.Math.ceil; import static java.lang.Math.sqrt; import ...
- IAR MSP430如何生成烧写文件
IAR生成430烧写方法有2种, 第一种是:将工程的debug模式切换成release模式,看图片操作. 那个.d43文件就是仿真调试模式的文件. 这里的test.txt文件就是烧写文件了,不要 ...
随机推荐
- Linux后台开发工具箱-葵花宝典
Linux后台开发工具箱-葵花宝典 一见 2016/11/4 目录 目录 1 1. 前言 4 2. 脚本类工具 4 2.1. 双引号和单引号 4 2.2. 取脚本完整文件路径 5 2.3. 环境变量和 ...
- select函数及fd_set介绍
1. select函数 1. 用途 在编程的过程中,经常会遇到许多阻塞的函数,好像read和网络编程时使用的recv, recvfrom函数都是阻塞的函数,当函数不能成功执行的时候,程序就会一直阻塞在 ...
- 【Python笔记】1、格式化输出(%用法和format用法)
转自:https://www.cnblogs.com/fat39/p/7159881.html 一.格式化输出1.整数的输出%o —— oct 八进制%d —— dec 十进制%x —— hex 十六 ...
- NOI2019 Day1游记
Day1挂了,没什么好说的... 开场T1想到70分暴力就走人了,后来发现可以写到85...(听说有人写dfs过了95?233333) T2刚了2个多小时,得到每次只在中间填最大值的结论后不会区间DP ...
- ES6基础-变量的解构赋值
作者 | Jeskson 来源 | 达达前端小酒馆 解构赋值: 数组的解构赋值,对象的解构赋值,字符串的解构赋值,数值与布尔值的解构赋值,函数参数的解构赋值. 开发环境准备: 编辑器,VS Code, ...
- ModuleNotFoundError: No module named 'rest_framework_swagger'
pip3.6 install django-rest-swagger
- SpringCloud:搭建基于Gateway的微服务网关(二)
0.代码 https://github.com/fengdaizang/OpenAPI 1.引入相关依赖 pom文件如下: <?xml version="1.0" encod ...
- phpstudy(小皮面板)和phpstudy2018 配置php的区别
phpstudy(小皮面板)和phpstudy2018 配置php的区别 一.总结 一句话总结: phpstudy(小皮面板) 和 phpstudy2018 只是引入的php的位置不同,但是核心代码还 ...
- 【转】干货篇:手机绕过BL锁9008模式强刷
<ignore_js_op> 高通QPST线刷其实就是利用高通芯片自带的9008端口,将手机系统内的所有分区的镜像文件,直接刷写手机.这个刷机方式比REC卡刷和fastboot线刷,更底层 ...
- Python80个练手项目列表
原文地址:https://www.shiyanlou.com/questions/102676/?utm_source=baidu&utm_medium=cpc&utm_campaig ...