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文件就是烧写文件了,不要 ...
随机推荐
- 12-网页,网站,微信公众号基础入门(编写后台PHP程序,实现Airkiss配网)
https://www.cnblogs.com/yangfengwu/p/11067590.html 首先说一下,这两个地方需要配置一样 网站根目录建个文件夹 airkiss的文件夹 里面放上 ind ...
- NodeJS基础学习总结
一.nodeJS解释 JS是脚本语言,脚本语言都需要一个解析器才能运行.对于写在HTML页面里的JS,浏览器充当了解析器的角色.而对于需要独立运行的JS,NodeJS就是一个解析器. 每一种解析器都是 ...
- 第02组 Alpha冲刺(3/4)
队名:十一个憨批 组长博客 作业博客 组长黄智 过去两天完成的任务:写博客,复习C语言 GitHub签入记录 接下来的计划:构思游戏实现 还剩下哪些任务:敲代码 燃尽图 遇到的困难:Alpha冲刺时间 ...
- mac 使用tesseract识别图片中的中文
安装 tesseractbrew install tesseract 加入环境变量export TESSDATA_PREFIX=/usr/local/Cellar/tesseract/4.1.0/sh ...
- 表格样式、表格css、
.mytab{ border-collapse: collapse;}.mytab tr,.mytab td,.mytab th{ text-align: center; border: 1px so ...
- select多选左移右移的实现
<html> <head> <meta http-equiv="Content-Type" content="text/html; char ...
- hdu2037 今年暑假不AC[贪心][区间调度问题]
目录 题目地址 题干 代码和解释 参考 题目地址 hdu2037 题干 代码和解释 本题使用贪心.有三种贪心策略:开始时间最早,结束时间最早,用时最短.第二种是正确的策略,因为结束得越早,后面就可以有 ...
- eggjs的参数校验模块egg-validate的使用和进一步定制化升级
简单讲一下这个egg-validate egg-validate是基于parameter的. 安装 npm install --save egg-validate 启用 // config/plugi ...
- Oracle 行转列 动态出转换的列
本文链接:https://blog.csdn.net/Huay_Li/article/details/82924443 10月的第二天,前天写了个Oracle中行转列的pivot的基本使用方法,然后, ...
- Python3基础 is与== 区别
Python : 3.7.3 OS : Ubuntu 18.04.2 LTS IDE : pycharm-community-2019.1.3 ...