将excel模板文件下载到angular6中的浏览器

将excel模板文件下载到angular6中的浏览器,angular,angular6,angular-file-upload,Angular,Angular6,Angular File Upload,我确实尝试过用SpringBoot下载angular6中的excel模板文件。在RESTAPI中,文件得到了正确的下载,但在将RESTAPI与angular集成时,excel文件得不到下载。任何人都可以帮忙 从angular到api的调用非常好 servivce.ts文件 download(data){ const REQUEST_PARAMS=new HttpParams().set('fileName',data.fileName); const REQUEST_URI='

我确实尝试过用SpringBoot下载angular6中的excel模板文件。在RESTAPI中,文件得到了正确的下载,但在将RESTAPI与angular集成时,excel文件得不到下载。任何人都可以帮忙

从angular到api的调用非常好

servivce.ts文件

 download(data){
    const REQUEST_PARAMS=new HttpParams().set('fileName',data.fileName);
    const REQUEST_URI='/downloadTemplate'; 
    // don't have any issue with url as eddit by me
     return this.http.get(REQUEST_URI,{
        params:REQUEST_PARAMS,
        responseType:'arraybuffer'
      })
    }
组件文件

download(){
    this.fileName='download.xlsx';
    const EXT=this.fileName.substr(this.fileName.lastIndexOf('.')+1);
    this.service.download({'fileName': this.fileName})
   .subscribe(response=>{
    saveAs(new Blob([response], {type:'application/vnc.openxmlformats-        officedocumnet.spreadsheetxml.sheet'}), this.fileName);
   })
  }

您需要添加
{responseType:'blob'}

试着这样做:

服务台

download(data){
    return  this.http.get(REQUEST_URI, { responseType: 'blob' })
}
组件技术

this.service.download({'fileName': this.fileName})
.subscribe(response=> {
    saveAs(response, this.fileName);
})

你尝试过这个解决方案吗?@AdritaSharma谢谢你的回答。按预期工作您的解决方案