当前位置:网站首页>Easyexcel single sheet and multi sheet writing
Easyexcel single sheet and multi sheet writing
2022-06-24 09:12:00 【DanceDonkey】
- single sheet Page write out
private static List<DataTemplate> data() {
return data(10);
}
private static List<DataTemplate> data(int size) {
List<DataTemplate> list = new ArrayList<>();
for (int i = 0; i < size; i++) {
DataTemplate data = new DataTemplate();
data.setMoney(i + 0.111);
data.setDate(new Date());
data.setValue(i + 0.111);
data.setUserid("userid " + i);
list.add(data);
}
return list;
}
public static void main(String[] args) {
String fileName = "D:\\Users\\lvhb\\Desktop\\templatewrite.xlsx";
EasyExcel.write(fileName, DataTemplate.class).sheet(" Templates ").doWrite(data());
}
single sheet There is no problem exporting pages
- many sheet Page export
@Test
public void test3(){
String fileName = "D:\\Users\\lvhb\\Desktop\\templatewrite.xlsx";
ExcelWriter excelWriter = EasyExcel.write(fileName).head(DataTemplate.class).build();
WriteSheet writeSheet = EasyExcel.writerSheet(0,"11").build();
excelWriter.write(data(10),writeSheet);
writeSheet = EasyExcel.writerSheet(1,"22").build();
excelWriter.write(data(20),writeSheet);
}
At this point, you may encounter file generation problems

It needs to be adjusted at this time excelWriter.finish() Method to write out all the data in the buffer .
excelWriter.finish();
- web download
@ResponseBody
@GetMapping("exportSheet")
public void exportSheet(HttpServletResponse response) throws Exception {
response.setContentType("application/force-download");// Set force download not to open
// response.setContentType("application/octet-stream");
response.setCharacterEncoding("UTF-8");
String filename = URLEncoder.encode(" Export data ", "UTF-8");
response.setHeader("Content-Disposition", "attachment; filename="+filename+".xlsx");// Pop up the download form
ServletOutputStream os = response.getOutputStream();
ExcelWriter excelWriter = EasyExcel.write(os).head(DataTemplate.class).build();
WriteSheet writeSheet = EasyExcel.writerSheet(0,"11111").build();
excelWriter.write(data(10),writeSheet);
writeSheet = EasyExcel.writerSheet(1,"2222222").build();
excelWriter.write(data(20),writeSheet);
excelWriter.finish();
os.close();
}
边栏推荐
- The list of open source summer winners has been publicized, and the field of basic software has become a hot application this year
- Leetcode -- wrong set
- 金仓KFS replicator安装(Oracle-KES)
- 12、 Demonstration of all function realization effects
- [noi simulation] pendulum (linear algebra, Du Jiao sieve)
- Transplantation of xuantie e906 -- fanwai 0: Construction of xuantie c906 simulation environment
- 110. balanced binary tree recursive method
- 2021-05-20computed and watch applications and differences
- RISC-V架构下 FPU Context 的动态保存和恢复
- PM2 deploy nuxt3 JS project
猜你喜欢

Every (), map (), forearch () methods. There are objects in the array

4275. Dijkstra sequence

数云发布2022美妆行业全域消费者数字化经营白皮书:全域增长破解营销难题

嵌入式 | 硬件转软件的几条建议

2022.06.23 (traversal of lc_144,94145\

【Redis实现秒杀业务①】秒杀流程概述|基本业务实现

Data midrange: detailed explanation of the technical stack of data acquisition and extraction

【LeetCode】541. 反转字符串 II

“论解不了数独所以选择做个数独游戏这件事”

Mba-day25 best value problem - application problem
随机推荐
P6698-[BalticOI 2020 Day2]病毒【AC自动机,dp,SPFA】
4274. suffix expression
From the Huawei weautomate digital robot forum, we can see the "new wisdom of government affairs" in the field of government and enterprises
【Redis实现秒杀业务①】秒杀流程概述|基本业务实现
华为路由器:ipsec技术
【输入法】迄今为止,居然有这么多汉字输入法!
【LeetCode】387. 字符串中的第一个唯一字符
读CVPR 2022目标检测论文得到的亿点点启发
1704. judge whether the two halves of a string are similar
解决:jmeter5.5在win11下界面上的字特别小
阿里资深软件测试工程师推荐测试人员必学——安全测试入门介绍
Digital cloud released the 2022 white paper on digital operation of global consumers in the beauty industry: global growth solves marketing problems
KaFormer个人笔记整理
Redis实现全局唯一ID
Unable to change the virtual machine power status and report an error solution
RISC-V架构下 FPU Context 的动态保存和恢复
玄铁E906移植----番外0:玄铁C906仿真环境搭建
[ES6 breakthrough] promise is comparable to native custom encapsulation (10000 words)
Every (), map (), forearch () methods. There are objects in the array
12、 Demonstration of all function realization effects