【发布时间】:2014-12-03 18:20:46
【问题描述】:
我想要做的只是一个用于将我的数据表导出到 Excel 的 XML 文档。
所以我需要的是这样的:
<?xml version="1.0" encoding="utf-8" standalone="yes"?>
<?mso-application Excel.Sheet?>
<Workbook xmlns="urn:schemas-microsoft-com:office:spreadsheet" xmlns:ss="urn:schemas-microsoft-com:office:spreadsheet" />
我正在使用System.Xml.Linq,我几乎拥有它,但我的代码不断在 Workbook 的前面添加“ss”。这是我的代码:
XDocument xmlssDoc2 = new XDocument(new XDeclaration("1.0", "utf-8", "yes"), new
XProcessingInstruction("mso-application", "Excel.Sheet"));
XNamespace aw = "urn:schemas-microsoft-com:office:spreadsheet";
XNamespace fc = "urn:schemas-microsoft-com:office:spreadsheet";
XElement root = new XElement(aw + "Workbook",
new XAttribute("xmlns", "urn:schemas-microsoft-com:office:spreadsheet"),
new XAttribute(XNamespace.Xmlns + "ss", "urn:schemas-microsoft-com:office:spreadsheet")
);
我得到的结果是:
<?xml version="1.0" encoding="utf-8" standalone="yes"?>
<?mso-application Excel.Sheet?>
<ss:Workbook xmlns="urn:schemas-microsoft-com:office:spreadsheet" xmlns:ss="urn:schemas-microsoft-com:office:spreadsheet" />
请帮忙!
【问题讨论】: