easypoi入门<1

学习自: http://www.afterturn.cn/doc/easypoi.html

开源地址: https://gitee.com/lemur/easypoi

https://gitee.com/lemur/easypoi-spring-boot-starter

maven项目,加入依赖

<dependency>
            <groupId>cn.afterturn</groupId>
            <artifactId>easypoi-base</artifactId>
            <version>3.2.0</version>
        </dependency>
        <dependency>
            <groupId>cn.afterturn</groupId>
            <artifactId>easypoi-web</artifactId>
            <version>3.2.0</version>
        </dependency>
        <dependency>
            <groupId>cn.afterturn</groupId>
            <artifactId>easypoi-annotation</artifactId>
            <version>3.2.0</version>
        </dependency>
View Code

需要导出的数据实体加上注解

/**
     * 名字
     */
    @Excel(name="名字")
    private String name;
    /**
     * 生日
     */
    @Excel(name="生日",format="yyyy-MM-dd",databaseFormat="yyyyMMddHHmmss")
    @DateTimeFormat(pattern = "yyyy-MM-dd")
    private Date birthday;
    /**
     * 性别(1:男 2:女)
     */
    @Excel(name="性别",replace= {"男_1","女_2"},suffix="生")
    private Integer sex;
    /**
     * 电子邮件
     */
    @Excel(name="电子邮件")
    private String email;
    /**
     * 电话
     */
    @Excel(name="电话")
    private String phone;
@RequestMapping("/loadExcel")
    public void downloadByPoiBaseView(ModelMap map, HttpServletRequest request,
            HttpServletResponse response) {
        //这个要考虑offic Excel 是2007还是2003.2007可以导百万数据; 2003只能导6万超过的是空白,数据量特别大建议分sheet导或者分条件导
        List<User> list = userService.excelList(null);//查询数据库数据
        //List<User> list = new ArrayList<>();
        //new ExportParams(String title,String sheet,String suffix);分别是表头,页名称,文件类型
        ExportParams params = new ExportParams("用户信息","用户信息",ExcelType.XSSF);
        params.setFreezeCol(10);//冻结列(分割线/无论有多少列,拖动左右滚动条一直显示的列.)
        params.setStyle(ExcelExportStylerColorImpl.class);//设置样式,自定义实现IExcelDataHandler<T>
        map.put(NormalExcelConstants.DATA_LIST, list);//数据
        map.put(NormalExcelConstants.CLASS, User.class);//类型
        map.put(NormalExcelConstants.PARAMS, params);//excel参数
        map.put(NormalExcelConstants.FILE_NAME, "用户信息");
        
        PoiBaseView.render(map, request, response, NormalExcelConstants.EASYPOI_EXCEL_VIEW);//无返回值下载
    }

 

原文地址:https://www.cnblogs.com/yxgmagic/p/9519854.html