angular: 前端TS把後臺數據導出word格式

exportWordCase() { // 導出word
    if (!this.suiteId) {
        this.msg.error('請選擇目錄!');
        return;
    }
    this.isSpinShow = true;
  
    let url = this.url + 'v1/testrom/export/word?suiteId=' + this.suiteId;
    this.http.get(url, '', { responseType: 'blob' }).subscribe((rest: any) => {
        let blob = new Blob([rest], { type: "application/vnd.openxmlformats-officedocument.wordprocessingml.document" });   

//導出的格式爲word
        let objectUrl = URL.createObjectURL(blob);
        let a = document.createElement('a');
        let fileName = this.suiteName + '.docx';
        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;
        }, 2000);
    });
}

 

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章