title: XML to Excel Mapping
body: <p>I try to export some data to Excel using XML. Here is an example of my code that generates the Excel file:</p>
  
  <pre><code>    Private Sub ExportToExcel()
      Dim fs As New IO.StreamWriter("exported.xls", False)
      fs.WriteLine("&lt;?xml version=""1.0""?&gt;")
      fs.WriteLine("&lt;?mso-application progid=""Excel.Sheet""?&gt;")
      fs.WriteLine("&lt;Workbook xmlns:ss=""urn:schemas-microsoft-com: Office:spreadsheet""&gt;")
  
      ' Create the styles for the worksheet
      fs.WriteLine(" &lt;Styles&gt;")
  
      ' Style for the column headers
      fs.WriteLine(" &lt;Style ss:ID=""1""&gt;")
      fs.WriteLine(" &lt;Font ss:Bold=""1""/&gt;")
      fs.WriteLine(" &lt;Alignment ss:Horizontal=""Center"" ss:Vertical=""Center"" " &amp; _
      "ss:WrapText=""1""/&gt;")
      fs.WriteLine(" &lt;Interior ss:Color=""#C0C0C0"" ss:Pattern=""Solid""/&gt;")
      fs.WriteLine(" &lt;/Style&gt;")
  
      ' Style for the column information
      fs.WriteLine(" &lt;Style ss:ID=""2""&gt;")
      fs.WriteLine(" &lt;Alignment ss:Vertical=""Center"" ss:WrapText=""1""/&gt;")
      fs.WriteLine(" &lt;/Style&gt;")
      fs.WriteLine(" &lt;/Styles&gt;")
  
      ' Write the worksheet contents
      fs.WriteLine("&lt;Worksheet ss:Name=""Data Export""&gt;")
      fs.WriteLine(" &lt;Table&gt;")
  
      For i As Integer = 0 To 1
          fs.WriteLine(" &lt;Row&gt;")
          For j As Integer = 0 To 2
              fs.WriteLine(" &lt;Cell&gt;")
              fs.WriteLine(" &lt;Data ss:Type=""String""&gt;H&lt;/Data&gt;")
              fs.WriteLine(" &lt;/Cell&gt;")
          Next
          fs.WriteLine(" &lt;/Row&gt;")
      Next
  
          ' Close up the document
          fs.WriteLine(" &lt;/Table&gt;")
          fs.WriteLine("&lt;/Worksheet&gt;")
          fs.WriteLine("&lt;/Workbook&gt;")
  
          fs.Close()
  
  End Sub
  </code></pre>
  
  <p>And this is what I have in my generated xls file:</p>
  
  <pre><code>    &lt;?xml version="1.0"?&gt;
  &lt;?mso-application progid="Excel.Sheet"?&gt;
  &lt;Workbook xmlns:ss="urn:schemas-microsoft-com: Office:spreadsheet"&gt;
   &lt;Styles&gt;
   &lt;Style ss:ID="1"&gt;
   &lt;Font ss:Bold="1"/&gt;
   &lt;Alignment ss:Horizontal="Center" ss:Vertical="Center" ss:WrapText="1"/&gt;
   &lt;Interior ss:Color="#C0C0C0" ss:Pattern="Solid"/&gt;
   &lt;/Style&gt;
   &lt;Style ss:ID="2"&gt;
   &lt;Alignment ss:Vertical="Center" ss:WrapText="1"/&gt;
   &lt;/Style&gt;
   &lt;/Styles&gt;
  &lt;Worksheet ss:Name="Data Export"&gt;
   &lt;Table&gt;
   &lt;Row&gt;
   &lt;Cell&gt;
   &lt;Data ss:Type="String"&gt;H&lt;/Data&gt;
   &lt;/Cell&gt;
   &lt;Cell&gt;
   &lt;Data ss:Type="String"&gt;H&lt;/Data&gt;
   &lt;/Cell&gt;
   &lt;Cell&gt;
   &lt;Data ss:Type="String"&gt;H&lt;/Data&gt;
   &lt;/Cell&gt;
   &lt;/Row&gt;
   &lt;Row&gt;
   &lt;Cell&gt;
   &lt;Data ss:Type="String"&gt;H&lt;/Data&gt;
   &lt;/Cell&gt;
   &lt;Cell&gt;
   &lt;Data ss:Type="String"&gt;H&lt;/Data&gt;
   &lt;/Cell&gt;
   &lt;Cell&gt;
   &lt;Data ss:Type="String"&gt;H&lt;/Data&gt;
   &lt;/Cell&gt;
   &lt;/Row&gt;
   &lt;/Table&gt;
  &lt;/Worksheet&gt;
  &lt;/Workbook&gt;
  </code></pre>
  
  <p>Seems to be correct, but when I open the xls I have a crazy output:<img src="https://i.stack.imgur.com/GV8z7.png" alt="enter image description here"></p>
  
  <p>But it is not everything: if I write manualy the xml structure to my xsl file (or I copy-paste it from another file for example) the output is ok - I see my rows &amp; columns with right values (H,H,H everywhere), formatting, the name of the worksheet is "Data Export" as I set it... don't understand :( Please, explain me someone. Thanks a lot!!!</p>