<c r="C1" t="s" xmlns="">
<v>1</v>
</c>
导致我重新打开EXCEL时没有显示我新增C1单元格的值
通过打开EXCEL sheet1.xml将xmlns=""属性去除后
再打开EXCEL就能显示了
代码:
XDocument xdoc = XDocument.Load(read);List<XElement> lst = xdoc.Document.Descendants().Where(p => p.Name.LocalName == "row" &&Convert.ToInt32(p.Attribute("r").Value) == 1).ToList();XElement xelementChild = new XElement("v");xelementChild.Value = "1";XElement xelement = new XElement("c",xelementChild); xelement.SetAttributeValue("r", "C1");xelement.SetAttributeValue("t", "s"); lst[0].Add(xelement);
生成的文件
<row r="1" spans="1:2" x14ac:dyDescent="0.15" xmlns:x14ac="http://schemas.microsoft.com/office/spreadsheetml/2009/9/ac" xmlns="http://schemas.openxmlformats.org/spreadsheetml/2006/main"> <c r="A1" t="s"> <v>0</v> </c> <c r="B1" t="s"> <v>1</v> </c> <c r="C1" t="s" xmlns=""> <v>1</v> </c></row>