栏目分类:
子分类:
返回
名师互学网用户登录
快速导航关闭
当前搜索
当前分类
子分类
实用工具
热门搜索
名师互学网 > IT > 软件开发 > 后端开发 > Java

easypoi导出excel

Java 更新时间: 发布时间: IT归档 最新发布 模块sitemap 名妆网 法律咨询 聚返吧 英语巴士网 伯小乐 网商动力

easypoi导出excel

文章目录
  • 一、easypoi是什么?
  • 二、使用步骤
    • 1、导入pom依赖
    • 2、实体类
    • 3、导出测试


后端 :SpringBoot + EasyPOI + MyBatis
数据库 :MySQL

一、easypoi是什么?

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());
        }
    }
转载请注明:文章转载自 www.mshxw.com
本文地址:https://www.mshxw.com/it/342908.html
我们一直用心在做
关于我们 文章归档 网站地图 联系我们

版权所有 (c)2021-2022 MSHXW.COM

ICP备案号:晋ICP备2021003244-6号