title: C# Generated Excel File: File Format or File Extension is not valid
body: <p>I'm calling the action "Export" where i pass a list of viewmodels and define the format</p>
  
  <pre><code>public ActionResult DownloadTokenlist(string startDate = null, string endDate = null)
              {        
                  using (HRCTSStatisticDb db = new HRCTSStatisticDb(Setting.ClientId))
                  {    
                      List&lt;TokenExportViewModel&gt; tokenExportViewModels = new List&lt;TokenExportViewModel&gt;();
  
                      Response.AddHeader("content-disposition", $"attachment;filename=Tokenlist_{DateTime.Now.ToString("dd.MM.yyyy")}.xlsx");
                      log.InfoFormat($"The {new HomeController().UserRole(Context.LoggedInUser)}: {Context.LoggedInUser} has used the exceldownload");
  
                      return File(new ExcelExport().Export(tokenExportViewModels), "application/vnd.openxmlformats-officedocument.spreadsheetml.sheet");
                  }
              }
  </code></pre>
  
  <p>The action i call (ExcelEngine is by Syncfusion):</p>
  
  <pre><code>public MemoryStream Export(List&lt;TokenExportViewModel&gt; list)
      {
          MemoryStream stream = new MemoryStream();
          using (ExcelEngine excelEngine = new ExcelEngine())
          {
              IApplication application = excelEngine.Excel;
              application.DefaultVersion = ExcelVersion.Excel2010;
              IWorkbook workbook = application.Workbooks.Create(1);
              IWorksheet worksheet = workbook.Worksheets.Create("Tokenlist");
  
              IStyle defaultStyle = workbook.Styles.Add("default");
              defaultStyle.Font.Size = 12;
  
              worksheet.SetDefaultColumnStyle(1, 20, defaultStyle);
              worksheet.SetDefaultRowStyle(1, 300, defaultStyle);
  
              worksheet.UsedRange.AutofitColumns();
              worksheet.Range["A1"].Text = $"Tokenlist - {DateTime.Today.ToString("dd.MM.yyyy")}";
              worksheet.Range["A1"].CellStyle = h1Style;
              workbook.SaveAs(stream);
              workbook.Close();
          }
          return stream;
      }
  </code></pre>
  
  <p>I only posted the code which has an impact on the file and (maybe) could create the error. 
  There is no error, until i open the file, then this exception pops up:</p>
  
  <blockquote>
    <p>Excel cannot open the file 'Tokenlist_22.05.2018.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>I've tried to change the file format to .xls and .vbs but neither works. With .xls I can open the document but then it has no data in it.</p>
  
  <p>The .close() doesn't change much, it just closes the output stream previously opened.</p>