Angular下載文件

  public Down(path: string) {

    return this.http.get(path, { responseType: "blob" }).subscribe((results) => {

      this.saveExcel(results, "導出數據");
    });

  }
  /**
  * 請求成功以後保存成excel文件(基本導出方法,請求成功以後調用)
  * @param data
  * @param name
  */
  public saveExcel(data: Blob, name: string) {
    var a = document.createElement('a');
    var blob = new Blob([data], { 'type': "application/vnd.ms-excel" });
    a.href = URL.createObjectURL(blob);
    a.download = name + ".csv";
    a.click();
  }
相關文章
相關標籤/搜索