title: openXML spreadsheetdocument return byte array for MVC file download
body: <p>I'm trying to return a openXML spreadsheetdocument as a byte[] which I can then use to allow my MVC to send that file to a user. here is my spreadsheetdocument method to return the byte array</p>
  
  <pre><code>using (MemoryStream mem = new MemoryStream())
  {
      SpreadsheetDocument spreadsheetDocument = SpreadsheetDocument.
          Create(mem, SpreadsheetDocumentType.Workbook);
  
      // Add a WorkbookPart to the document.
      WorkbookPart workbookpart = spreadsheetDocument.AddWorkbookPart();
      workbookpart.Workbook = new Workbook();
  
      // Add a WorksheetPart to the WorkbookPart.
      WorksheetPart worksheetPart = workbookpart.AddNewPart&lt;WorksheetPart&gt;();
      worksheetPart.Worksheet = new Worksheet(new SheetData());
  
      // Add Sheets to the Workbook.
      Sheets sheets = spreadsheetDocument.WorkbookPart.Workbook.
          AppendChild&lt;Sheets&gt;(new Sheets());
  
      SheetData sheetData = worksheetPart.Worksheet.GetFirstChild&lt;SheetData&gt;();
  
      //row start
      for (int id = 0; id &lt;= reports.Count(); id++)
      {
          if (id == 0)
          {
              Row contentRow = CreateContentRow(reports.ElementAt(id), true, 2 + id);
              sheetData.AppendChild(contentRow);
          }
          else
          {
              Row contentRow = CreateContentRow(reports.ElementAt((id - 1)), false, 2 + id);
              sheetData.AppendChild(contentRow);
          }
      }
  
      // Append a new worksheet and associate it with the workbook.
      Sheet sheet = new Sheet()
      {
          Id = spreadsheetDocument.WorkbookPart.
              GetIdOfPart(worksheetPart),
          SheetId = 1,
          Name = "mySheet"
      };
      sheets.Append(sheet);
      workbookpart.Workbook.Save();
      return mem.ToArray();
  }
  </code></pre>
  
  <p>then in my MVC controller i call it like this</p>
  
  <pre><code>return File(crs.CreateReportSpreadSheet(reports),"application/vnd.openxmlformats-officedocument.spreadsheetml.sheet", "Reports.xlsx");
  </code></pre>
  
  <p>the file downloads, but when you go to open it shows an error message that the file is corrupted. Is there any other way to allow them to download this file?</p>