Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<p>Ok, I got this working, though through some effort. To create the stream:</p> <pre><code>MemoryStream stream = new MemoryStream(); using (SpreadsheetDocument package = SpreadsheetDocument.Create(stream, SpreadsheetDocumentType.Workbook)) { Excel.CreateSpreadsheet(package, Excel_Methods.CreateSpotQuoteOut(), true); } stream.Seek(0, SeekOrigin.Begin); System.Net.Mail.Attachment attach = new System.Net.Mail.Attachment(stream, "spreadsheet.xlsx"); attach.ContentDisposition.CreationDate = DateTime.Now; attach.ContentDisposition.ModificationDate = DateTime.Now; attach.ContentDisposition.Inline = false; attach.ContentDisposition.Size = stream.Length; attach.ContentType.MediaType = "application/vnd.openxmlformats-officedocument.spreadsheetml.sheet"; </code></pre> <p>Also, I found that mine were not being sent right after I created them, and the reason for that is "standalone=yes" was not being added to the xml declaration of all the pages, so in my AddParts function, after adding the parts, I passed them into this function:</p> <pre><code>private static void AddXMLStandalone(OpenXmlPart part) { System.IO.StreamWriter writer = new System.IO.StreamWriter(part.GetStream()); XmlDocument doc = new XmlDocument(); doc.Load(part.GetStream()); doc.InnerXml = doc.InnerXml.Substring(doc.InnerXml.IndexOf("?&gt;") + 2); doc.InnerXml = "&lt;?xml version=\"1.0\" encoding=\"UTF-8\" standalone=\"yes\"?&gt;" + doc.InnerXml; part.GetStream().SetLength(doc.InnerXml.Length); doc.Save(writer); writer.Flush(); writer.Close(); } </code></pre> <p>Good luck!</p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload