I'm trying to write a 2003 XML Excel file, but maybe I'm missing something big, or... I simply don't understand namespaces.
I need to write this:
<?xml version="1.0" encoding="utf-8"?>
<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">
<Worksheet Name="Questions">
<Table><Row><Cell><Data ss:Type="Number">1</Data></Cell></row></table>
</Worksheet>
And I am using code like this one:
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 );
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".
In the Data nodes, instead of getting a node like
<Data ss:Type="Number">
, I get<Data d6p1:ss="String" xmlns:d6p1="Type">
, which I don't really understand. I've also tried with:dataForQuestionNumber.SetAttribute( "ss", "Type", "Number" );
But it does not seems to work.