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);
        }
  • 相关阅读:
    linux删除/var/log/下面所有日志 如何重新记录日志
    DIV里的内容自动换行
    it冲突:commit your changes or stash them before you can merge. 解决办法
    git切换到远程分支
    【异常】warning: refname 'feature1.3.0' is ambiguous.导致git merge失败
    在此篇文章中,我们将用 15 分钟对 PHP v7.x 版本更改进行简要回顾
    input元素所有type类型及相关作用
    微信自动关闭内置浏览器页面,返回公众号窗口 WeixinJSBridge.call('closeWindow')
    css背景渐变色
    数组的forEach和map和for方法的区别
  • 原文地址:https://www.cnblogs.com/mytzq/p/12016310.html
Copyright © 2011-2022 走看看