目录
一、在pom.xml文件中导入easypoi依赖
二、准备一个Student实体类
三、编辑Controller层代码
一、在pom.xml文件中导入easypoi依赖
复制代码
1
2
3
4
5<dependency> <groupId>cn.afterturn</groupId> <artifactId>easypoi-spring-boot-starter</artifactId> <version>3.3.0</version> </dependency>
二、准备一个Student实体类
复制代码
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17@Data @AllArgsConstructor @NoArgsConstructor @Accessors(chain = true) public class Student { /** * name:对应excel中的列名 * orderNum:自动获取某个字段在 Excel 中的列的位置 * width:excel中每一列的宽度 */ @Excel(name = "编号",orderNum = "0",width = 15) private Integer id; @Excel(name = "姓名",orderNum = "0",width = 15) private String name; @Excel(name = "地址",orderNum = "0",width = 15) private String address; }
三、编辑Controller层代码
复制代码
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22@RestController @GetMapping("/export") public class ScrmCustomerInfoController { /** * 导出查询到的数据到excel表中 * @param response */ public void export(HttpServletResponse response){ //定义一个list集合来存放数据 List<Student> list = new ArrayList<Student>(); //给学生对象存入数据 Student student = new Student(); student.setId(001).setName("张三").setAddress("成都市双流区"); //将学生数据存入List集合中 list.add(student); try { ExcelUtils.exportExcel(list, "titleName", "sheetName", CustomerInfoVO.class, "fileName", response); } catch (IOException e) { e.printStackTrace(); } } }
最后
以上就是端庄电源最近收集整理的关于利用EasyPoi导出数据到Excel表的全部内容,更多相关利用EasyPoi导出数据到Excel表内容请搜索靠谱客的其他文章。
本图文内容来源于网友提供,作为学习参考使用,或来自网络收集整理,版权属于原作者所有。
发表评论 取消回复