Writing Excel 2003 with C#

spamvi

New Member
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:\[code\]<?xml version="1.0" encoding="utf-8"?><Workbookxmlns="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>\[/code\]And I am using code like this one:\[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\][*]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 \[code\]<Data ss:Type="Number">\[/code\], I get \[code\]<Data d6p1:ss="String" xmlns:d6p1="Type">\[/code\], which I don't really understand. I've also tried with:dataForQuestionNumber.SetAttribute( "ss", "Type", "Number" );But it does not seems to work.
 
Back
Top