ali Excel 的导出
1。引入maven依赖
<dependency> <groupId>com.alibaba</groupId> <artifactId>easyexcel</artifactId> <version>1.1.2-beta5</version> </dependency>
2.在实体类上加上注解
@ExcelProperty(value = "列名",index = 列的索引)
实体类要继承 BaseRowModel 类
3.
List<实体类> list= 获取要导出的数据集合。 Sheet sheet = new Sheet(1,0,实体类.class); //定义一个sheet
try {
response.setHeader("Access-Control-Expose-Headers","Content-disposition");
response.setHeader("Content-disposition","attachment;filename=" + URLEncoder.encode(sheetName,"utf-8") + ".xlsx");
OutputStream out = response.getOutputStream();
ExcelWriter writer = EasyExcelFactory.getWriter(out); //
sheet.setSheetName(sheetName); //设置sheet的名字
writer.write(list,sheet); //把list集合中的数据写入到sheet上面
writer.finish();
} catch (IOException e) {
logger.info("导出表格出现问题" + e.getMessage());
}