title: ASP.NET MVC - Download Excel file from MemoryStream (Corrupt file)
body: <p>I'm trying to make an Excel file download using the in-build downloading in browsers. Basically the download is working fine, after I've created the Excel file within my controller, but when I'm trying to open this file in Excel, I'm told that the file is corrupted:</p>
  
  <blockquote>
    <p>Excel cannot open the file 'Report.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.</p>
  </blockquote>
  
  <p>When forcing the file to open in Excel, the sheet is simply empty. I have no idea why this is.</p>
  
  <p><strong>Code</strong></p>
  
  <p>I'm not showing how I'm creating the Excel file, as that's irrelevant (<em>it worked fine before using memory stream</em>).</p>
  
  <pre><code>var stream = wBook.WriteXLSX(); // Return a MemoryStream (Using DTG.Spreadsheet)
  
  return File(stream, "application/vnd.openxmlformats-officedocument.spreadsheetml.sheet", "Report.xlsx");
  </code></pre>