当前位置:网站首页>【文件下载】Easyexcel快速上手
【文件下载】Easyexcel快速上手
2022-07-29 05:06:00 【没有BUG就是最大的BUG】
一、引入依赖
<!-- Easyexcel-->
<dependency>
<groupId>com.alibaba</groupId>
<artifactId>easyexcel</artifactId>
<version>2.1.3</version>
</dependency>
<!-- POI-->
<dependency>
<groupId>org.apache.poi</groupId>
<artifactId>poi</artifactId>
<version>3.17</version>
</dependency>
<dependency>
<groupId>org.apache.poi</groupId>
<artifactId>poi-ooxml</artifactId>
<version>3.17</version>
</dependency>
<dependency>
<groupId>org.apache.poi</groupId>
<artifactId>poi-ooxml-schemas</artifactId>
<version>3.17</version>
</dependency>
<dependency>
<groupId>org.apache.poi</groupId>
<artifactId>poi-scratchpad</artifactId>
<version>3.17</version>
</dependency>
<dependency>
<groupId>org.apache.poi</groupId>
<artifactId>poi-excelant</artifactId>
<version>3.17</version>
</dependency>二、实体类注解配置
@Data
public class User {
@ExcelProperty("用户名")
private String username;
@ExcelProperty("密码")
private String password;
@ExcelProperty("性别")
private String age;
public User(String username, String password, String age) {
this.username = username;
this.password = password;
this.age = age;
}
}
三、业务代码
@GetMapping("download")
public void download(HttpServletResponse response) throws IOException {
List<User> list = new ArrayList<>();
list.add(new User("张三","aaa","男"));
list.add(new User("李四","bbb","女"));
list.add(new User("王五","ccc","男"));
response.setContentType("application/vnd.openxmlformats-officedocument.spreadsheetml.sheet");
response.setCharacterEncoding("utf-8");
response.setHeader("Content-disposition", "attachment; filename=用户.xlsx");
EasyExcel.write(response.getOutputStream(), User.class).sheet("用户").doWrite(list);
}四、接口访问(文件存放位置可自定义)

五、查看文件

边栏推荐
- Stack and queue and priority queue (large heap and small heap) simulation implementation and explanation of imitation function
- EMI interference troubleshooting with near-field probe and current probe
- Conv2d of torch
- P2181 diagonal
- Use annotation test in idea
- 荣耀2023内推,内推码ambubk
- 新产品上市最全推广方案
- JS (in ES6) sync & await understanding
- 让你的正则表达式可读性提高一百倍
- 【微信小程序】swiper滑动页面,滑块左右各露出前后的一部分,露出一部分
猜你喜欢

Solution | get the relevant information about the current employees' highest salary in each department |

Using jupyter (I), install jupyter under windows, open the browser, and modify the default opening address

深度学习刷SOTA的一堆trick

1 sentence of code, get asp Net core binds multiple sources to the same class

Reveal installation configuration debugging

Google gtest事件机制

Take you to understand JS array

How does word view document modification traces? How word views document modification traces

Network Security Learning - Intranet Security 1

Unity Metaverse(三)、Protobuf & Socket 实现多人在线
随机推荐
Using jupyter (I), install jupyter under windows, open the browser, and modify the default opening address
Learn matlab to draw geographical map, line scatter bubble density map
学习数据库的第一个程序
Mapper agent development
Exception - ...MaxUploadSizeExceededException: Maximum upload size exceeded; nested exception is ...
Solve the warning prompt of MySQL mapping file
Google gtest事件机制
Excel卡住了没保存怎么办?Excel还没保存但是卡住了的解决方法
EF Core: 一对一,多对多的配置
Original code, inverse code, complement code
Northeast University Data Science Foundation (matlab) - Notes
2021-10-11
How is the entered query SQL statement executed?
On prepayment of house purchase
pytorch学习笔记
JDBC statement + resultset introduction
The most comprehensive promotion plan for the launch of new products
What if the office prompts that the system configuration cannot run?
Big silent event Google browser has no title
Leetcode 763. partition labels divide alphabetic intervals (medium)