0

I have next code and I have 2 problems after try execute: 1. System.Xml.XmlException: The ':' character, hexadecimal value 0x3A, cannot be included in a name. 2. base {System.SystemException} = {Can not re-define the prefix'' from'' to 'urn = schemas-microsoft-com: office: excel' within the same start element tag.} {"No se puede volver a definir el prefijo '' de '' a 'urn=schemas-microsoft-com:office:excel' dentro de la misma etiqueta de elemento inicial."}

My code is:

XDocument xdoc = new XDocument(new XDeclaration("1.0", "utf-8", "yes"),
   new XElement("Document", 
          new XElement("Worbook", 
               new XElement("DocumentProperties", new XElement("Author", "YO"), 
                                                       new XElement("Created",DateTime.Today),
                                                       new XElement("Company","CIA")),
                                   new XElement("ExcelWorkBook", new XElement("WindowHeight","6795"),
                                                            new XElement("WindowWidth","8460"),
                                                            new XElement("WindowTopX","120"),
                                                            new XElement("WindowTopY","15"),
                                                            new XElement("ProtectStructure","False"),
                                                            new XElement("ProtectWindows","False")
                                                ),
                                    new XElement("Styles", new XElement("Style", new XAttribute("ss:ID", "Default"), new XAttribute("ss:Name", "Normal"), 
                                                                                new XElement("Alignment", "", new XAttribute("ss:Vertical","Bottom")), 
                                                                                new XElement("Borders", ""), 
                                                                                new XElement("Font", ""), 
                                                                                new XElement("Interior", ""), 
                                                                                new XElement("NumberFormat", ""), 
                                                                                new XElement("Protection", "")
                                                                        ),
                                                        new XElement("Style",new XAttribute("ss:ID","s21"), new XElement("Font", "", new XAttribute("x:Family", "Swiss"), new XAttribute("ss:Bold", "1")))
                                                ),
                                    new XElement("Worksheet",new XAttribute ("ss:Name","Sheet1"),
                                                                   new XElement("Table", new XAttribute("ss:ExpandedColumnCount", "2"), 
                                        new XAttribute("ss:ExpandedRowCount", "5"),
                                        new XAttribute("x:FullColumns","1"),
                                        new XAttribute("x:FullRows","1"),
                                                                                    new XElement("Row", new XElement("Cell", new XElement("Data", 
                                                    new XAttribute("ss:Type","String"), "Text in cell A1"))),
                                                                                    new XElement("Row", new XElement("Cell", new XElement("Data", new XAttribute("ss:Type", "String"), "Bold text in cell A2"))),
                                                                                    new XElement("Row", new XAttribute("ss:Index", "4"), new XElement("Cell", new XAttribute("ss:Index", "2"), 
                                                            new XElement("Data", new XAttribute("ss:Type", "Number"), "43"))),
                                                                                    new XElement("Row", new XElement("Cell", new XAttribute("ss:Index", "2"), 
                                                    new XAttribute("ss:Formula", "=R[-1]C/2"), 
                                                    new XElement("Data", new XAttribute("ss:Type", "Number"), "21.5")))),
                                                                new XElement("WorksheetOptions",
                                                                        new XAttribute("xmlns","urn=schemas-microsoft-com:office:excel"), 
                                                                        new XElement("Print", new XElement("ValidPrinterInfo", ""), 
                                                                                                            new XElement("HorizontalResolution", "600"),
                                                                                                            new XElement("VerticalResolution", "600")),
                                                                                             new XElement("Selected",""),
                                                                                             new XElement("Panes", new XElement("Pane", new XElement("Number","3"), 
                                                                                                                                        new XElement("ActiveRow", "5"), 
                                                                                                                                        new XElement("ActiveCol","1"))),
                                                                                             new XElement("ProtectObjects",""), new XElement("ProtectScenarios","False"))
                    )
    )
));

Regards, María

mpl
  • 31
  • 2
  • 10
  • I´m trying to copy the "Excel XML Spreadsheet example" from this link [link]http://en.wikipedia.org/wiki/Microsoft_Office_XML_formats#Excel_XML_Spreadsheet_example[/link] – mpl Nov 26 '13 at 12:15
  • 1
    You are missing xml namespaces. try http://stackoverflow.com/questions/4985974/xelement-namespaces-how-to – Erdogan Kurtur Nov 26 '13 at 16:21

0 Answers0