2
我想要做的是將我的數據表導出到Excel的XML文檔。如何在具有相同值的另一個名稱空間時將名稱空間指定給XAttribute?
所以我需要的是這樣的:
<?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
和我差不多有它,但我的代碼將不斷「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" />
任何幫助,請!
好工作!我在前一天問過這個問題,實際上最終做了類似的事情,但你的答案是現成的!感謝dbc! – 2014-12-05 11:59:40