EasyExcel导出多个sheet

控制层

 //导出数据字典接口
    @GetMapping("exportData")

    public void exportDict(HttpServletResponse response) throws IOException {
        dictService.exportDictData(response);
    }

业务层

//导出数据字典接口
    @Override
    public void exportDictData(HttpServletResponse response) throws IOException {
        //设置下载信息
        response.setContentType("application/vnd.ms-excel");
        response.setCharacterEncoding("utf-8");
        String fileName = "dict";
        response.setHeader("Content-disposition", "attachment;filename="+ fileName + ".xlsx");
        //查询数据库
        List<Dict> dictList = baseMapper.selectList(null);
       // baseMapper.selectAllll("666","hdiuhaihda");
        //Dict -- DictEeVo
        List<DictEeVo> dictVoList = new ArrayList<>();
        for(Dict dict:dictList) {
            DictEeVo dictEeVo = new DictEeVo();
           // dictEeVo.setId(dict.getId());
            BeanUtils.copyProperties(dict,dictEeVo);
            dictVoList.add(dictEeVo);}
        //调用方法进行写操作

        ExcelWriter excelWriter = EasyExcel.write(response.getOutputStream()).build();
        //获取sheet0对象
        WriteSheet mainSheet = EasyExcel.writerSheet(0, "模型信息").head(DictEeVo.class).build();
        //获取模型信息,向sheet0写入数据
        excelWriter.write(dictList,  mainSheet);

        //获取sheet1对象
        WriteSheet detailSheet = EasyExcel.writerSheet(1, "词条666信息").head(DictEeVo.class).build();

        excelWriter.write(dictList, detailSheet);
        //关闭流
        excelWriter.finish();
       /* try {
            EasyExcel.write(response.getOutputStream(), DictEeVo.class).sheet(0,"dict")
                    .doWrite(dictVoList);
            EasyExcel.write(response.getOutputStream(), DictEeVo.class).sheet(1,"dict1")
                    .doWrite(dictVoList);
        } catch (IOException e) {
            e.printStackTrace();
        }*/
    }

javabean

@Data
public class DictEeVo {

	@ExcelProperty(value = "id"  )
	@DateTimeFormat
	private Long id;


	@ExcelProperty(value = "名称")
	private String name;

	public Long getId() {
		return id;
	}

	public void setId(Long id) {
		this.id = id;
	}

	public String getName() {
		return name;
	}

	public void setName(String name) {
		this.name = name;
	}
}
package com.atguigu.yygh.model.cmn;

import com.atguigu.yygh.model.base.BaseEntity;
import com.baomidou.mybatisplus.annotation.*;
import com.fasterxml.jackson.annotation.JsonFormat;
import io.swagger.annotations.ApiModel;
import io.swagger.annotations.ApiModelProperty;
import lombok.Data;

import java.util.Date;
import java.util.HashMap;
import java.util.Map;

/**
 * <p>
 * Dict
 * </p>
 *
 * @author qy
 */
@Data
@ApiModel(description = "数据字典")
@TableName("t_test")
public class Dict {

    private static final long serialVersionUID = 1L;


    public Dict(Long id, String name, Date date) {
        this.id = id;
        this.name = name;
        this.date = date;
    }

    @ApiModelProperty(value = "id")
    private Long id;

    public static long getSerialVersionUID() {
        return serialVersionUID;
    }

    public Dict() {
    }

    public  Long getId() {
        return id;
    }

    public void setId(Long id) {
        this.id = id;
    }


    @ApiModelProperty(value = "名称")
    public String getName() {
        return name;

    }


    public void setName(String name) {
        this.name = name;
    }









    @ApiModelProperty(value = "名称")
    @TableField("name")
    private String name;

    public Date getDate() {
        return date;
    }

    public void setDate(Date date) {
        this.date = date;
    }

    @ApiModelProperty(value = "名称")
    @TableField("date")
    private Date date;


    @Override
    public String toString() {
        return "Dict{" +
                "id=" + id +
                ", name='" + name + '\'' +
                '}';
    }
}

 

 

评论 4
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值