我有下一个代码,尝试执行后遇到2个问题: 1. System.Xml.XmlException:':'字符,十六进制值0x3A,不能包含在名称中。 2. base {System.SystemException} = {无法在同一个开始元素标记内从''重新定义前缀''从''到'urn = schemas-microsoft-com:office:excel'。} {“No se puede volver a definir el prefijo''de''a'urn = schemas-microsoft-com:office:excel'dentro de la misma etiqueta de elemento inicial。“}
我的代码是:
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"))
)
)
));
此致 玛丽亚