继续潜水

导航

 

pom..xml

<dependency>
<groupId>com.alibaba</groupId>
<artifactId>easyexcel</artifactId>
<version>1.1.2-beat1</version>
</dependency>
AddCasesBindExl.java
package com.zjjw.cases.mode.exl;

import com.alibaba.excel.annotation.ExcelProperty;
import com.alibaba.excel.metadata.BaseRowModel;
import lombok.Data;

/**
 * @author tongzuqi
 * @date: 2019/12/10 9:26 AM
 */
@Data
public class AddCasesBindExl extends BaseRowModel {

    /**
     * 案件类型
     */
    private String casesTypeName;
    /**
     * 律师
     */
    @ExcelProperty(value ="律师",index = 0)
    private String lawyerName;
    /**
     * 律师电话
     */
    @ExcelProperty(value ="律师电话",index = 1)
    private String lawyerMobile;
    /**
     * 所属律所
     */
    @ExcelProperty(value ="所属律所",index = 2)
    private String lawyerOffice;
    /**
     * 单位编号
     */
    private String deptCode;
    /**
     * 单位名称
     */
    @ExcelProperty(value ="单位名称",index = 3)
    private String deptName;
    /**
     * 审核状态
     */
    private int auditStatus;
    /**
     * 审核状态名称
     */
    @ExcelProperty(value ="审核状态名称",index = 4)
    private String auditStatusStr;
    /**
     * 案件编号
     */
    private String casesCode;
    /**
     * 案件名称
     */
    @ExcelProperty(value ="案件名称",index = 5)
    private String casesName;
    /**
     * 创建时间
     */
    @ExcelProperty(value ="创建时间",index = 6)
    private String createTime;


}
ExportController.java
    /**
     * 新增案件列表统计
     * @return
     */
    @GetMapping("/addCasesBind")
    public void addCasesBindPage(HttpServletResponse response , StatisticsCasesBindFo statisticsRegisterFo)  throws Exception {
        ExcelWriter writer = null;
        OutputStream outputStream = response.getOutputStream();
        long startTime=System.currentTimeMillis();
        try {
            //添加响应头信息
            response.setHeader("Content-disposition", "attachment; filename=" + "新增案件列表.xlsx");
            response.setContentType("application/msexcel;charset=UTF-8");//设置类型
            response.setHeader("Pragma", "No-cache");//设置头
            response.setHeader("Cache-Control", "no-cache");//设置头
            response.setDateHeader("Expires", 0);//设置日期头

            //实例化 ExcelWriter
            writer = new ExcelWriter(outputStream, ExcelTypeEnum.XLSX, true);

            //实例化表单
            Sheet sheet = new Sheet(1, 0, AddCasesBindExl.class);
            sheet.setSheetName("sheel");
            //获取数据
            List<AddCasesBindExl> list  =  exportService.addCasesBindExport(statisticsRegisterFo);
            log.info("查询时间:{}s.条数:{}",(float)(System.currentTimeMillis()-startTime)/1000,list.size());

            startTime=System.currentTimeMillis();
            //输出
            writer.write(list, sheet);
            writer.finish();
            outputStream.flush();
        } catch (IOException e) {
            log.info("导出异常",e);
        } finally {
            try {
                response.getOutputStream().close();
            } catch (IOException e) {
                log.info("导出异常",e);
            }
        }
        log.info("导出:{}s",(float)(System.currentTimeMillis()-startTime)/1000);
    }

 

posted on 2019-12-10 14:11  继续潜水  阅读(1935)  评论(0编辑  收藏  举报