下载的带有 fileSaver 的 xlsx 文件在打开时无效

问题描述

我编写了一个函数,我想通过服务下载一个 xlsx 文件。下载到目前为止也有效。但是当我打开文件时,我收到错误消息文件扩展名或文件格式无效。我该如何解决问题?

代码

// Service
getDownloadplan(): Observable<any> {
    const url = `/download-plan?sales-plan=0&personnel-plan=0&investment-plan=0&loan-plan=0&material-cost-plan=0`;
    return this.http.get(`${environment.baseUrl}` + url,{ responseType: 'blob'});
  }
// TS
 downloadplanBwa() {
    this.planBwaService.getDownloadplan().subscribe(response => {
      const downloadFile: any = new Blob([response],{  type: 'application/vnd.openxmlformats-officedocument.spreadsheetml.sheet' });
      fileSaver.saveAs(downloadFile,'Plan');
    },error => console.log('ERROR'),() => console.log('SUCCESSFUL')
    );
  }

如果我使用 MIME-Type application/vnd.ms-excel;charset=utf-8 这是针对 xls 格式的,那么它可以工作。

我需要在代码中更改什么才能成功打开 xlsx 文件

解决方法

暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!

如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。

小编邮箱:dio#foxmail.com (将#修改为@)