- 一、easypoi是什么?
- 二、使用步骤
- 1、导入pom依赖
- 2、实体类
- 3、导出测试
后端 :SpringBoot + EasyPOI + MyBatis
数据库 :MySQL
easypoi对poi进一步封装了,通过简单的注解和模板语言,完成以前复杂的写法,提高的开发效率
二、使用步骤 1、导入pom依赖
cn.afterturn
easypoi-spring-boot-starter
4.2.0
2、实体类
package com.cykj.bean;
import cn.afterturn.easypoi.excel.annotation.Excel;
import lombok.Data;
import java.io.Serializable;
@Data
public class BrandInfo implements Serializable {
@Excel(name = "stuid", width = 25, orderNum = "0")
private Integer stuid;
@Excel(name = "stuacc", width = 25, orderNum = "0")
private String stuacc;
@Excel(name = "stuname", width = 25, orderNum = "0")
private String stuname;
@Excel(name = "stuidcard", width = 25, orderNum = "0")
private String stuidcard;
@Excel(name = "stuexamnum", width = 25, orderNum = "0")
private String stuexamnum;
@Excel(name = "stusex", width = 20, orderNum = "1")
private String stusex;
@Excel(name = "stuage", width = 20, orderNum = "1")
private String stuage;
}
3、导出测试
@GetMapping("/exportExcel")
public void exportExcel(HttpServletResponse response) {
// 获取用户信息
List list = excelService.UserTbFy();
try {
// 设置响应输出的头类型及下载文件的默认名称
String fileName = new String("demo信息表.xls".getBytes("utf-8"), "ISO-8859-1");
response.addHeader("Content-Disposition", "attachment;filename=" + fileName);
response.setContentType("application/vnd.ms-excel;charset=gb2312");
//导出
Workbook workbook = ExcelExportUtil.exportExcel(new ExportParams(), BrandInfo.class, list);
workbook.write(response.getOutputStream())
} catch (IOException e) {
log.info("请求 exportExcel 异常", e.getMessage());
}
}



