Angular2调用后端接口完成Excel导出

Angular2响应后端的Excel导出

设置一个导出按钮

样式可以采用zorro.官网:https://ng.ant.design/docs/introduce/zh

html

<!-- 参数为查询条件-->
<button nz-button nzType="default"  (click)="excelOne(year,month)" ><i class="anticon anticon-file-excel"></i>导出</button>

component

@Injectable()
export class NbBusinessFormService {
  constructor(private bpmHttp: NbHttp) {
  } 

excelOne(year, month) {
    const exyear = this.year;
    const exmonth = this.month;
     
    this.doExcelExport(exyear, exmonth).subscribe((exportResult) => {
        
      const blob = new Blob([exportResult], { type: 'application/vnd.openxmlformats-officedocument.spreadsheetml.sheet' });
        const objectUrl = URL.createObjectURL(blob);
        const a = document.createElement('a');
        document.body.appendChild(a);
        a.setAttribute('style', 'display: none');
        a.setAttribute('href', objectUrl);
        a.setAttribute('download', exyear + '年' + exmonth + '月份' + '供应商详情.xlsx');
        a.click();
        document.body.removeChild(a);
        URL.revokeObjectURL(objectUrl);
      this.supLoading = false;
      }
    );
 }

//导出
  doExcelExport(exyear: number, exmonth: number, supplierName: string) {
    const options: RequestOptionsArgs = {
      headers: new Headers({ 'Content-Type': 'application/json;charset=utf-8' }),
      responseType: ResponseContentType.Blob
    };
    return this.bpmHttp.fullPost("连接后台路径url自定义", { year: exyear, month: exmonth}, options);
  }

}
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值