title: Writing Excel 2003 with C#
body: <p>I'm trying to write a 2003 XML Excel file, but maybe I'm missing something big, or... I simply don't understand namespaces.</p>
  
  <p>I need to write this:</p>
  
  <pre><code>&lt;?xml version="1.0" encoding="utf-8"?&gt;
  &lt;Workbook
  xmlns="urn:schemas-microsoft-com:office:spreadsheet"
  xmlns:o="urn:schemas-microsoft-com:office:office"
  xmlns:x="urn:schemas-microsoft-com:office:excel"
  xmlns:ss="urn:schemas-microsoft-com:office:spreadsheet"
  xmlns:html="http://www.w3.org/TR/REC-html40"&gt;
  
  &lt;Worksheet Name="Questions"&gt;
  &lt;Table&gt;&lt;Row&gt;&lt;Cell&gt;&lt;Data ss:Type="Number"&gt;1&lt;/Data&gt;&lt;/Cell&gt;&lt;/row&gt;&lt;/table&gt;
  &lt;/Worksheet&gt;
  </code></pre>
  
  <p>And I am using code like this one:</p>
  
  <pre><code>    var toret = new XmlDocument();
  
      // Add encoding declaration
      XmlDeclaration xmlDeclaration = toret.CreateXmlDeclaration( "1.0", "utf-8", null);
      toret.AppendChild( xmlDeclaration );
  
      // Add root label
      var root = toret.CreateElement( ExcelXmlLblWorkbook );
      toret.AppendChild( root );
  //  root.SetAttribute( "xmlns", "urn:schemas-microsoft-com:office:spreadsheet" );
      root.SetAttribute( "xmlns:o", "urn:schemas-microsoft-com:office:office" );
      root.SetAttribute( "xmlns:x", "urn:schemas-microsoft-com:office:excel" );
      root.SetAttribute( "xmlns:ss", "urn:schemas-microsoft-com:office:spreadsheet" );
      root.SetAttribute( "xmlns:html", "http://www.w3.org/TR/REC-html40" );
  
      // ...
      var cellForQuestionNumber = wsQuestions.OwnerDocument.CreateElement( ExcelXmlLblCell );
      row.AppendChild( cellForQuestionNumber );
  
      var dataForQuestionNumber = wsQuestions.OwnerDocument.CreateElement( ExcelXmlLblData );
      dataForQuestionNumber.SetAttribute( "ss:Type", "Number" );
      dataForQuestionNumber.InnerText = "1";
      cellForQuestionNumber.AppendChild( dataForQuestionNumber );
  </code></pre>
  
  <ol>
  <li><p>If I try to create the root node with the attribute for the xmlns="..." then it fails at runtime saying that "the namespace name is invalid".</p></li>
  <li><p>In the Data nodes, instead of getting a node like <code>&lt;Data ss:Type="Number"&gt;</code>, I get <code>&lt;Data d6p1:ss="String" xmlns:d6p1="Type"&gt;</code>, which I don't really understand. I've also tried with:</p>
  
  <p>dataForQuestionNumber.SetAttribute( "ss", "Type", "Number" );</p></li>
  </ol>
  
  <p>But it does not seems to work.</p>