当前位置:网站首页>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());
}
}边栏推荐
- Question note 4 (the first wrong version, search the insertion position)
- Brother Ali teaches you how to correctly understand the problem of standard IO buffer
- 3D modeling tool Archicad 26 newly released
- Nowcode- learn to delete duplicate elements in the linked list (detailed explanation)
- MD5加密验证
- 【深度学习】:《PyTorch入门到项目实战》第九天:Dropout实现(含源码)
- 关于Bug处理的一些看法
- 累计出货130亿颗Flash,4亿颗MCU!深度解析兆易创新的三大产品线
- parseJson
- MD5 encryption verification
猜你喜欢

技术分享 | 误删表以及表中数据,该如何恢复?

Comprehensively design an oppe homepage -- page service part

【深度学习】:《PyTorch入门到项目实战》第七天之模型评估和选择(上):欠拟合和过拟合(含源码)

负整数及浮点数的二进制表示

【深度学习】:《PyTorch入门到项目实战》第四天:从0到1实现logistic回归(附源码)

Applet: scroll view slides to the bottom by default

Learn to use MySQL explain to execute the plan, and SQL performance tuning is no longer difficult

Binary representation of negative integers and floating point numbers

College students participated in six Star Education PHP training and found jobs with salaries far higher than those of their peers

Interesting kotlin 0x0a:fun with composition
随机推荐
概率论与数理统计第一章
PostgreSQL每周新闻—2022年7月20日
Summary of kubenertes 1.16 cluster deployment problems
13 differences between MySQL and Oracle
3D modeling tool Archicad 26 newly released
【深度学习】:《PyTorch入门到项目实战》第二天:从零实现线性回归(含详细代码)
Leetcode647. Palindrome substring
Simple addition, deletion, modification and query of commodity information
NoSQL introduction practice notes I
Signal shielding and processing
MySQL 5.7 and sqlyogv12 installation and use cracking and common commands
【深度学习】:《PyTorch入门到项目实战》第六天:多层感知机(含代码)
SUSE CEPH rapid deployment – storage6
Leetcode learn complex questions with random pointer linked lists (detailed explanation)
[deep learning]: the second day of pytorch introduction to project practice: realize linear regression from zero (including detailed code)
[learn slam from scratch] publish the coordinate system transformation relationship to topic TF
技术分享 | MySQL Shell 定制化部署 MySQL 实例
Alibaba cloud - Wulin headlines - site building expert competition
Outline and principle of structured design -- modularization
How to set ticdc synchronization data to only synchronize the specified library?