title: Downloading Excel file xlsx in Angularjs and WebApi
body: <p><br/>I am working on a task, in which I have to download a report in xlsx format. The report file is generated successfully from server, and is received on client side as well. But it is not opening and producing invalid format error.<br/><br/>Below is the code of server side.<br/></p>
  
  <pre><code>var output = await reportObj.GetExcelData(rParams);
      if (output != null){
          var result = new HttpResponseMessage(HttpStatusCode.OK)
          {
              Content = new ByteArrayContent(output.ConentBytes)
          };
          result.Content.Headers.ContentType = new MediaTypeHeaderValue("application/vnd.openxmlformats-officedocument.spreadsheetml.sheet");
          result.Content.Headers.ContentDisposition = new ContentDispositionHeaderValue("attachment")
          {
              FileName = output.FileName
          };
   return result;
   }
  </code></pre>
  
  <p><br/>Here is the code for client side:<br/></p>
  
  <pre><code>        var saveData = function (response) {
  
          if (response.status === 200) {
              var reportData = response.data;
  
              var b = new Blob([reportData], { type: "application/vnd.openxmlformats-officedocument.spreadsheetml.sheet" });
              saveAs(b,"ReportFile.xlsx");//this is FileSaver.js function
          } else {
              console.log(response.statusText);
          }
  
      };
  
  
      $scope.getExcelFile = function(reportName, reportParams) {
  
          reportDataService.getExcelReportData(reportName, reportParams, saveData);
  
      }
  </code></pre>
  
  <p><br/><strong>Below is the error message:</strong><br/>
  Excel could not open newFile.xlsx because some content is unreadable. Do you want to open and repair this workbook?<br/><br/>
  <strong>On clicking repair, following error appears:</strong>
  Excel cannot open this file.<br/>
  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.
  <br/><br/>Can some one guide me what I am doing wrong? Meanwhile, the same server side file generator objects works smoothly in ASP.Net forms application, and the file opens without any error as well.
  <br/>Thank you.</p>