当前位置:网站首页>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());
}
}边栏推荐
- SUSE CEPH add nodes, reduce nodes, delete OSD disks and other operations – storage6
- 做题笔记5(有序数组的平方)
- Alibaba cloud - Wulin headlines - site building expert competition
- Re12:读论文 Se3 Semantic Self-segmentation for Abstractive Summarization of Long Legal Documents in Low
- Rsync 服务部署与参数详解
- Huawei mate 40 series exposure: large curvature hyperboloid screen, 5nm kylin 1020 processor! There will also be a version of Tianji 1000+
- 负整数及浮点数的二进制表示
- 概率论与数理统计第一章
- 做题笔记2(两数相加)
- Re14:读论文 ILLSI Interpretable Low-Resource Legal Decision Making
猜你喜欢

Interesting kotlin 0x09:extensions are resolved statically
![[deep learning]: day 1 of pytorch introduction to project practice: data operation and automatic derivation](/img/4e/a41eee56fc0e8d3089f105bcb63155.png)
[deep learning]: day 1 of pytorch introduction to project practice: data operation and automatic derivation

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

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

Tcp/ip related

Probability theory and mathematical statistics Chapter 1

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

Comprehensively design an oppe homepage -- after sales service of the page
![[deep learning]: model evaluation and selection on the seventh day of pytorch introduction to project practice (Part 1): under fitting and over fitting (including source code)](/img/19/18d6e94a1e0fa4a75b66cf8cd99595.png)
[deep learning]: model evaluation and selection on the seventh day of pytorch introduction to project practice (Part 1): under fitting and over fitting (including source code)

HTAP comes at a price
随机推荐
Probability theory and mathematical statistics Chapter 1
Tcp/ip related
【深度学习】:《PyTorch入门到项目实战》第一天:数据操作和自动求导
epoll水平出发何边沿触发
go语言慢速入门——流程控制语句
Question making note 2 (add two numbers)
Text filtering skills
Understanding of asmlinkage
Best Cow Fences 题解
Summary of kubenertes 1.16 cluster deployment problems
Comprehensively design an oppe homepage -- page service part
快速掌握 Kotlin 集合函数
RE14: reading paper illsi interpretable low resource legal decision making
Semtech launched Lora edge, a geolocation solution for the Internet of things, and the first chip lr1110 is now on the market
Efficiency comparison of three methods for obtaining timestamp
SUSE Ceph 快速部署 – Storage6
ERROR: transport library not found: dt_ socket
有趣的 Kotlin 0x06:List minus list
获取时间戳的三种方法的效率比较
小程序:获取元素节点信息