当前位置:网站首页>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();
}
边栏推荐
- Microblog writing - flow chart - sequence chart - Gantt chart - Mermaid flow chart - good results
- GradScaler MaxClipGradScaler
- “论解不了数独所以选择做个数独游戏这件事”
- 【LeetCode】387. 字符串中的第一个唯一字符
- Data middle office: detailed explanation of technical architecture of data middle office
- 荐书丨《好奇心的秘密》:一个针尖上可以站多少跳舞的小天使?
- 浮点数表示法(总结自CS61C和CMU CSAPP)
- Leetcode -- wrong set
- 520. detect capital letters
- P6117-[JOI 2019 Final]コイン集め【贪心】
猜你喜欢

A tip to read on Medium for free

听说你还在花钱从网上买 PPT 模板?

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

【LeetCode】415. String addition

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

I heard that you are still spending money to buy ppt templates from the Internet?

2022.06.23 (traversal of lc_144,94145\

How to configure environment variables and distinguish environment packaging for multi terminal project of uniapp development

【LeetCode】415. 字符串相加
![[redis implements seckill business ①] seckill process overview | basic business implementation](/img/a3/9a50e83ece43904a3a622dcdb05b3c.png)
[redis implements seckill business ①] seckill process overview | basic business implementation
随机推荐
Depens:*** but it is not going to be installed
Redis实现全局唯一ID
MySQL | view notes on Master Kong MySQL from introduction to advanced
从华为WeAutomate数字机器人论坛,看政企领域的“政务新智理”
tcpdump抓包实现过程
Data middle office: middle office architecture and overview
P6698-[BalticOI 2020 Day2]病毒【AC自动机,dp,SPFA】
Pytorch读入据集(典型数据集及自定义数据集两种模式)
荐书丨《好奇心的秘密》:一个针尖上可以站多少跳舞的小天使?
Target detection series fast r-cnn
2020 China's provinces and cities, three-level linkage data, data agencies (data from the official website of the National Bureau of Statistics)
听说你还在花钱从网上买 PPT 模板?
"I can't understand Sudoku, so I choose to play Sudoku."
阿里资深软件测试工程师推荐测试人员必学——安全测试入门介绍
PM2 deploy nuxt3 JS project
Array opposite pointer series
读CVPR 2022目标检测论文得到的亿点点启发
The printed object is [object object]. Solution
Ebanb B1 Bracelet brush firmware abnormal interrupt handling
2021-05-20computed and watch applications and differences