title: file is corrupt and cannot be opened when saving an excel document using openXML 2.0
body: <p>I am trying to save rows pass through to this method from another spreadsheet and save this spreadsheet as an attachment to an email. The email sends fine, but the attachment does not open with the error "file is corrupt and cannot be opened". I tried saving the file to a filstream on the c: but got the same error. What is wrong with this code?</p>
  
  <pre><code> public static void CreateErrorMailWithExcelAttachment(List&lt;Row&gt; rows)
          {
              if (rows.Count &gt; 0)
              {
                  using (MemoryStream stream = new MemoryStream())
                  {
                      //Create a spreadsheet document by supplying the file name.
                      using (SpreadsheetDocument spreadsheetDocument = SpreadsheetDocument.Create(stream, SpreadsheetDocumentType.Workbook))
                      {
  
                          // Add a WorkbookPart to the document.
                          spreadsheetDocument.AddWorkbookPart();
                          spreadsheetDocument.WorkbookPart.Workbook = new Workbook();
  
                          spreadsheetDocument.WorkbookPart.AddNewPart&lt;WorksheetPart&gt;();
                          spreadsheetDocument.WorkbookPart.WorksheetParts.First().Worksheet = new Worksheet();
  
                          // create sheet data
                          spreadsheetDocument.WorkbookPart.WorksheetParts.First().Worksheet.AppendChild(new SheetData());
  
                          // Add Rows to the Sheet.
                          foreach (Row row in rows)
                          {
                              spreadsheetDocument.WorkbookPart.WorksheetParts.First().Worksheet.First().AppendChild(new Row(row.OuterXml));
                          }
  
                          spreadsheetDocument.WorkbookPart.Workbook.Save();
                      }
  
                      Dictionary&lt;string, byte[]&gt; attachments = new Dictionary&lt;string, byte[]&gt;();
                      attachments.Add("Book1.xlsx", stream.ToArray());
  
                      SendEmail
                          (
                              acsis.Common.AppContext.Configuration.GetValue(Constants.ApplicationName, "SMTPServer"),
                              acsis.Common.AppContext.Configuration.GetValue(Constants.ApplicationName, "SMTPUser"),
                              acsis.Common.AppContext.Configuration.GetValue(Constants.ApplicationName, "SMTPPass"),
                              "shaun.bosch@acsis.co.za",
                              acsis.Common.AppContext.Configuration.GetValue(Constants.ApplicationName, "InstitutionalDatabaseAdminEmail"),
                              "Failed rows from bulk investor spreadsheet upload",
                              "Test",
                              false,
                              attachments
                          );
                  }
              }
          }
  </code></pre>