angular: 前端TS把后台数据导出Excel格式

downLoadTemplet() { // 下载excel模板
    if (!this.suiteId) {
        this.msg.error('请选择目录!');
        return;
    }
    this.isSpinShow = true;
    let url = this.url + 'v1/testrom/export/template';
    this.http.get(url, { 'project': this.project }, { responseType: 'blob' }).subscribe((rest: any) => {
        let blob = new Blob([rest], { type: "application/vnd.openxmlformats-officedocument.spreadsheetml.sheet" });  //导出的格式为excel
        let objectUrl = URL.createObjectURL(blob);
        let a = document.createElement('a');
        let fileName = "Template" + '.xlsx';
        document.body.appendChild(a);
        a.setAttribute('style', 'display:none');
        a.setAttribute('href', objectUrl);
        a.setAttribute('download', fileName);
        a.click();
        URL.revokeObjectURL(objectUrl);
        setTimeout(() => {
            this.isSpinShow = false;
        }, 1000);
    });
}
发布了99 篇原创文章 · 获赞 60 · 访问量 30万+

猜你喜欢

转载自blog.csdn.net/lengyuewusheng99/article/details/84256051