当前位置:网站首页>【文件下载】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);
}
四、接口访问(文件存放位置可自定义)
五、查看文件
边栏推荐
- [wechat applet -- solve the alignment problem of the last line of display:flex. (discontinuous arrangement will be divided into two sides)]
- 带你搞懂 Kubernetes 集群中几种常见的流量暴露方案
- 【微信小程序】swiper滑动页面,滑块左右各露出前后的一部分,露出一部分
- 软件测试面试题(四)
- Leetcode 763. partition labels divide alphabetic intervals (medium)
- 【config】配置数组参数
- Torch.nn.crossentropyloss() details
- Traffic flow prediction pit climbing record (I): traffic flow data set, original data
- pytorch学习笔记
- [wechat applet] swiper slides the page, and the left and right sides of the slider show part of the front and back, showing part of the front and back
猜你喜欢
力扣------对奇偶下标分别排序
Activity workflow table structure learning
Northeast University Data Science Foundation (matlab) - Notes
How is the entered query SQL statement executed?
What if excel is stuck and not saved? The solution of Excel not saved but stuck
Learn matlab to draw geographical map, line scatter bubble density map
WPS如何进行快速截屏?WPS快速截屏的方法
1 sentence of code, get asp Net core binds multiple sources to the same class
【微信小程序--解决display:flex最后一行对齐问题。(不连续排列会分到两边)】
SGuard64.exe ACE-Guard Client EXE:造成磁盘经常读写,游戏卡顿,及解决方案
随机推荐
Big silent event Google browser has no title
Wechat picture identification
Implementation of flutter gesture monitoring and Sketchpad
【config】配置数组参数
五个关联分析,领略数据分析师一大重要必会处理技能
EF Core: 一对一,多对多的配置
Go memory model for concurrency
1 sentence of code, get asp Net core binds multiple sources to the same class
那个准时上下班,从不愿意加班加点的人,在我前面升职了...
iOS面试准备 - ios篇
Use more flexible and convenient Rogowski coil
EMI interference troubleshooting with near-field probe and current probe
un7.28:redis客户端常用命令。
带你搞懂 Kubernetes 集群中几种常见的流量暴露方案
【2022新生学习】第三周要点
pytorch学习笔记
How to set row height and column width in excel? The method of setting row height and column width in Excel
MySQL time calculation function
How does WPS use smart fill to quickly fill data? WPS method of quickly filling data
How to install Office2010 installation package? How to install Office2010 installation package on computer