当前位置:网站首页>Easypoi multi sheet export by template
Easypoi multi sheet export by template
2022-07-28 17:04:00 【Zhengx Hui】
One .pom Dependency import
<dependency>
<groupId>cn.afterturn</groupId>
<artifactId>easypoi-spring-boot-starter</artifactId>
<version>4.0.0</version>
</dependency>Two . Template settings
1. In the project creation excel Catalog

2. The configuration template (dataList,dataList2 They are the exported data sets , The names have to be the same ;fe Represents loop insertion ,t Is a collection element object ,‘{ {’ Start ,‘}}’ end )
sheet1
sheet2
3、 ... and . Code implementation
1. Set entity DataEntity(Data2Entity similar )
@Data
public class DataEntity implements Serializable {
private static final long serialVersionUID = 1L;
private String id;
private String data1;
private String data2;
private String data3;
private String data4;
private String data5;
private String data6;
private String data7;
private String data8;
private String data9;
private String data10;
private String data11;
private String data12;
private String data13;
}
2. obtain dataList(dataList2 similar )
public List<DataEntity> getDataList(Map<String, Object> param) {
return testDataServiceImpl.getDataList(param);
}3. export
public void exportDataExcel(Map<String, Object> param, HttpServletRequest request, HttpServletResponse response) {
try {
String fileName = "test";
String fileUrl = System.getProperty("user.dir") + "/excel/test.xlsx";
TemplateExportParams params = new TemplateExportParams(fileUrl, true);
params.setStyle(ExcelStyleType.BORDER.getClazz());
params.setSheetNum(5);
Map<String, Object> map = new HashMap<String, Object>();
map.put("dataList", getDataList(param));
map.put("dataList2", getData2List(param));
Workbook book = ExcelExportUtil.exportExcel(params, map);
// Download method
export(response, book, fileName);
} catch (Exception e) {
throw new RuntimeException(" Export exception ");
}
} public void export(HttpServletResponse response, Workbook workbook, String fileName) throws Exception {
try {
response.setHeader("Access-Control-Allow-Origin", "*");
response.setCharacterEncoding("UTF-8");
response.setHeader("content-Type", "application/vnd.ms-excel");
response.setHeader("Content-Disposition",
"attachment;filename=" + URLEncoder.encode(fileName + ".xlsx", "UTF-8"));
OutputStream output = response.getOutputStream();
workbook.write(output);
output.flush();
workbook.close();
output.close();
} catch (Exception e) {
throw new IOException(e.getMessage());
}
}边栏推荐
- Probability theory and mathematical statistics Chapter 1
- After paying $1.8 billion in royalties to Qualcomm, Huawei reportedly ordered 120million chips from MediaTek! Official response
- Installation of QT learning
- In 2020q2, shipments in the global tablet market soared by 26.1%: Huawei ranked third and Lenovo increased the most!
- Understanding of asmlinkage
- Global mobile communication base station market in 2019: Ericsson, Huawei and Nokia ranked in the top three
- 做题笔记2(两数相加)
- [deep learning]: day 6 of pytorch introduction to project practice: multi-layer perceptron (including code)
- 【深度学习】:《PyTorch入门到项目实战》第七天之模型评估和选择(上):欠拟合和过拟合(含源码)
- Leetcode70 suppose you are climbing stairs. You need n steps to reach the roof. You can climb one or two steps at a time. How many different ways can you climb to the roof?
猜你喜欢

Call DLL file without source code

PostgreSQL每周新闻—2022年7月20日

结构化设计的概要与原理--模块化

Brother Ali teaches you how to correctly understand the problem of standard IO buffer

Interesting kotlin 0x07:composition

Binary representation of negative integers and floating point numbers
![[deep learning]: day 6 of pytorch introduction to project practice: multi-layer perceptron (including code)](/img/19/18d6e94a1e0fa4a75b66cf8cd99595.png)
[deep learning]: day 6 of pytorch introduction to project practice: multi-layer perceptron (including code)

Leetcode learn to insert and sort unordered linked lists (detailed explanation)

MySQL 5.7 and sqlyogv12 installation and use cracking and common commands
![[deep learning]: day 4 of pytorch introduction to project practice: realize logistic regression from 0 to 1 (with source code)](/img/19/18d6e94a1e0fa4a75b66cf8cd99595.png)
[deep learning]: day 4 of pytorch introduction to project practice: realize logistic regression from 0 to 1 (with source code)
随机推荐
【深度学习】:《PyTorch入门到项目实战》第四天:从0到1实现logistic回归(附源码)
技术分享 | MySQL Shell 定制化部署 MySQL 实例
Egg (19): use egg redis performance optimization to cache data and improve response efficiency
Programmers from entry to roast!!!!
parseJson
大学生参加六星教育PHP培训,找到了薪水远超同龄人的工作
MySQL5.7及SQLyogV12安装及使用破解及常用命令
Tcp/ip related
Binary representation of negative integers and floating point numbers
SUSE CEPH add nodes, reduce nodes, delete OSD disks and other operations – storage6
Leetcode647. Palindrome substring
做题笔记4(第一个错误的版本,搜索插入位置)
有趣的 Kotlin 0x0A:Fun with composition
累计出货130亿颗Flash,4亿颗MCU!深度解析兆易创新的三大产品线
技术分享 | 误删表以及表中数据,该如何恢复?
Record the processing process of CEPH two RBDS that cannot be deleted
综合设计一个OPPE主页--页面服务部分
ERROR: transport library not found: dt_ socket
Leetcode learn complex questions with random pointer linked lists (detailed explanation)
Signal and slot mechanism of QT learning