title: Unable to download excel file from src/assets in development/qa/prod environment for angular application
body: <p>I am working with angular-7 application. I have sample excel file in src/assets. I have implemented a download attachment method to download sample excel file. I am able to download it but I am getting an error when I open downloaded sample excel file. <strong>The error description is: Excel cannot open the file 'sample.xlsx' because the file format or file extension is not valid. Verify that the file has not been corrupted and that the file extension matches the format of the file.</strong></p>
  
  <p><strong>component.component.html</strong></p>
  
  <pre><code>&lt;button mat-raised-button (click)="downloadexcelfile()"&gt;
  &lt;button mat-raised-button (click)="download()"&gt;
  
  </code></pre>
  
  <p><strong>component.component.ts</strong></p>
  
  <pre><code>downloadexcelfile() {
  
  if(navigator.msSaveBlob) {
  // to support in IE 10+
  let data: any;
  this.HttpClient.get("./assets/sample.xlsx",{responseType: "blob"}).subscribe((res:any) =&gt; { 
  data = res;
  
  // approach - 1
  let csvData = new Blob([data], { type: 'text/csv;charset=utf-8;'});
  
  // approach - 2
  let csvData = new Blob([data], { type: 'application/vnd.ms-excel'});
  
  // approach - 3
  let csvData = new Blob([data], { type: 'application/vnd.openxmlformats-officedocument.spreadsheetml.sheet'});
  
  navigator.msSaveBlob(csvData, "sample.xlsx");
  })
  
  }
  
  else if(!navigator.msSaveBlob) {
  let link = document.createElement("a");
  link.href = "assets/sample.xlsx";
  link.download = "sample.xlsx";
  link.click();
  window.URL.revokeObjectURL(link.href);
  link.remove();
  }
  
  }
  
  // approach - 4
  download() {
  
  if(navigator.msSaveBlob) {
  // to support in IE 10+
  let data: any;
  this.HttpClient.get("./assets/sample.xlsx",{responseType: "arraybuffer"}).subscribe((res:any) =&gt; { 
  data = res;
  
  // approach - 5
  let csvData = new Blob([data], { type: 'text/csv'});
  
  // approach - 6
  let csvData = new Blob([data], { type: 'application/vnd.ms-excel'});
  
  // approach - 7
  let csvData = new Blob([data], { type: 'application/vnd.openxmlformats-officedocument.spreadsheetml.sheet'});
  
  navigator.msSaveBlob(csvData, "sample.xlsx");
  })
  
  }
  
  else if(!navigator.msSaveBlob) {
  let link = document.createElement("a");
  link.href = "assets/sample.xlsx";
  link.download = "sample.xlsx";
  link.click();
  window.URL.revokeObjectURL(link.href);
  link.remove();
  }
  
  }
  </code></pre>
  
  <p>I have tried with multiple approaches and spent like 5 days to resolve this. still, I am trying to figure out. Could anyone please help me with this. Thanks in advance.</p>