zoukankan      html  css  js  c++  java
  • springboot easyexcel

    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);
        }
  • 相关阅读:
    c语言--第零次作业
    Beta 冲刺(3/7)
    Beta 冲刺(2/7)
    福大软工 · 第十次作业
    Beta 冲刺(1/7)
    BETA 版冲刺前准备(团队)
    Alpha 事后诸葛亮(团队)
    Alpha冲刺(10/10)
    Alpha 冲刺 (9/10)
    Alpha 冲刺 (8/10)
  • 原文地址:https://www.cnblogs.com/mytzq/p/12016310.html
Copyright © 2011-2022 走看看