0
即时尝试格式化XML文件,以便可以使用Microsoft Excel直接打开它。无法为Excel格式化Xml
im的问题是由于默认命名空间和别名ss:namespace是相同的。否则我不能让excel接受文件。
尝试下面的代码时,我在WorkSheet节点上获得了额外的xmlns =“”属性。这使Excel无法打开文件。
XNamespace nsDefault = "urn:schemas-microsoft-com:office:spreadsheet";
XElement workbook = new XElement(nsDefault + "Workbook",
new XAttribute("xmlns", nsDefault),
new XAttribute(XNamespace.Xmlns + "ss", nsDefault));
XElement worksheet = new XElement("Worksheet");
worksheet.SetAttributeValue(nsDefault + "Name", "Shipping");
XElement table = new XElement("Table");
XElement row = new XElement("Row");
XElement cell = new XElement("Cell");
XElement data = new XElement("Data");
data.SetAttributeValue(nsDefault + "Type", "String");
data.Value = "qwerty";
cell.Add(data);
row.Add(cell);
table.Add(row);
worksheet.Add(table);
workbook.Add(worksheet);
workbook.Save(@".\Xml\Test.xml");
有没有人知道我该如何解决这个问题?
为什么你自己发明轮子呢?你有没有看过直接创建符合MS-XML的文件的OpenXML? (http://openxmldeveloper.org/) – basti
Excel 2010?或旧版本? – code4life
Excel 2010.我会看看openxml,谢谢 – user1029697