公共部分

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写文件的更多相关文章

  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. Problem 1 珠江夜游 (cruise .cpp)———2019.10.6

    Problem 1 珠江夜游 (cruise.cpp)[题目描述]小 Z 放假后难得来一趟广州游玩,当然要吃遍广州各路美食小吃然后再到珠江新城看看远近闻名的小蛮腰啦!可当小 Z 一路吃吃吃以后,天渐渐 ...

  2. MyBatis框架,增删改查

    一.recourses中核心配置文件mybatis-config.xml 二. recourse中jdbc.properties 三.entity实体类 四.Dao层 五.ISmbmsUserDao. ...

  3. mac 搭建Java Spring boot 环境(idea)

    首先安装插件 安装下面的这个插件 然后重启idea,新建工程 选择新建 Springboot 框架 改写项目名称 选择类型 设置工程名称 删除多余的文件 编译工程 然后运行 1. 2. 参考: htt ...

  4. glew的安装

    下载链接: https://sourceforge.net/project/downloading.php?group_id=67586&filename=glew-1.5.1-win32.z ...

  5. mark一下咕掉的题目

    蒟蒻才普及组呀~ 大佬别D我 等集中补一下 CF980F:咋说捏,我觉得要联赛了做这题有点浪费时间,等想颓废了再来写写叭qwq 215E/279D/288E/331C3/431D/433E/750G/ ...

  6. lintcode-720重排带整数字符串

    题目描述: 给一包含大写字母和整数(从 0 到 9)的字符串, 试写一函数返回有序的字母以及数字和. 样例 给出 str = AC2BEW3, 返回 ABCEW5字母按字母表的顺序排列, 接着是整数的 ...

  7. HSBImageView--android--可以设置HSB值的imageview

    package guide.yunji.com.guide.view; import android.content.Context; import android.content.res.Typed ...

  8. 从ASP.NET到ASP.NET Core差异变化

    MSDN原文:链接 ASP.NET Core项目为开发人员提供了针对.NET Core,.NET Framework2种实现方式,根据官网通告NETCORE3.0后将取消对.NET Framework ...

  9. t6_sumdoc

    C:\Users\Administrator\Documents\sumdoc 2019\sumdoc t6 final\sumdoc t615C:\Users\Administrator\Docum ...

  10. [转]详解vue父组件传递props异步数据到子组件的问题

    原文地址:https://www.cnblogs.com/goloving/p/9114389.html 案例一 父组件parent.vue // asyncData为异步获取的数据,想传递给子组件使 ...