《下载excel模板》

前言:

        项目架构:

                       前端框架:Angular6 + ng-zorro-antd

                       后端架构:SSM + Dubbo:springMVC + spring + myBatis-plus
         接下来请跟随小编来看看下载excel模板是如何实现的呢?

正文:

                                                                                          前端

   一。html,下载按钮实现

<button nz-button [ngStyle]="table_button_downTemplate" (click)="downTemplate()">下载模板</button>

    二。component.ts,交互代码

  downTemplate() {
    const url = 'demo-web/foo/downFooTemplate';
    const downURL = this.http.getserverUrl(url);
    window.open(downURL);
    URL.revokeObjectURL(downURL);
  }

                                                                                         后端

     一。核心代码实现

public boolean downTemplate(HttpServletResponse response) {
        Map<Serializable, Serializable> map = new HashMap<>(16);
        List<FooTemplate> templateList = new ArrayList<>();
        FooTemplate fooTemplate = new FooTemplate();
        fooTemplate.setUserCode("111111141021");
        fooTemplate.setUserName("张三");
        fooTemplate.setTelNum("1573262524913");
        fooTemplate.setSex("女");
        fooTemplate.setStartTime("2018/10/20");
        fooTemplate.setFooGroupName("财务部");
        templateList.add(fooTemplate);
        //excel设置
        map.put(SHEET_NAME, "用户信息");
        map.put(COLUMNS, new String[]{"userCode", "userName", "telNum", "sex", "startTime", "fooGroupName"});
        map.put(TITLE, "用户信息模板:入职日期格式需为日期格式");
        map.put(NAME, "用户信息模板");
        map.put(DATA_LIST, (Serializable) templateList);

        try {
            ExcelUtil.exportExcel(map, response);
            return true;
        }catch (Exception e){
            return false;
        }
    }

结语:

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 3
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 3
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值