Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<p>Microsoft defined an XML Spreadsheet format that is compatible with Excel 2002 and later. I've used and have been very happy with it. On MSDN there is a <a href="http://msdn.microsoft.com/en-us/library/aa140062%28office.10%29.aspx" rel="nofollow noreferrer">gentle introduction</a> and some <a href="http://msdn.microsoft.com/en-us/library/aa140066%28office.10%29.aspx" rel="nofollow noreferrer">nitty-gritty documentation</a>.</p> <p>Here's a brief piece of code illustrating how you would use it:</p> <pre><code>public void WriteExcelDocument(string filename, string[,] values) { using (var writer = XmlWriter.Create(filename)) { const string ss = "urn:schemas-microsoft-com:office:spreadsheet"; writer.WriteProcessingInstruction("mso-application", "progid=\"Excel.Sheet\""); writer.WriteStartElement("ss", "Workbook", ss); writer.WriteStartElement("Worksheet", ss); writer.WriteAttributeString("Name", ss, "Sheet1"); writer.WriteStartElement("Table", ss); for (var i = 0; i &lt; values.GetLength(0); i++) { writer.WriteStartElement("Row", ss); for (var j = 0; j &lt; values.GetLength(1); j++) { writer.WriteStartElement("Cell", ss); writer.WriteStartElement("Data", ss); // Valid types are: Number, DateTime, Boolean, String, Error. // To keep the example simple, I'm just doing strings. writer.WriteAttributeString("Type", ss, "String"); // If the cell contains a boolean, be sure to write "0" or "1" here, not // "false" or "true". Again, I'm just doing strings, so it doesn't matter. writer.WriteString(values[i, j]); writer.WriteEndElement(); writer.WriteEndElement(); } writer.WriteEndElement(); } writer.WriteEndElement(); writer.WriteEndElement(); writer.WriteEndElement(); } } </code></pre> <p>Feel free to take this code and use it or modify it as you see fit. I'm releasing it under the MIT license. This is just a starting point; you could modify it to handle different data types, column widths, styling, multiple worksheets, etc.</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