public static void Node2XML(IEnumerable <KeyValuePair <string, object> > data, XmlNode node, XmlDocument docu) { var doc = data as FreeDocument; if (doc != null) { foreach (var item in doc.DataItems.OrderBy(d => d.Key)) { if (item.Value is IDictionary <string, object> ) { var dict = item.Value as IDictionary <string, object>; var newNode = docu.CreateNode(XmlNodeType.Element, item.Key, ""); Node2XML(dict, newNode, docu); node.AppendChild(newNode); } else { var attr = docu.CreateAttribute(FileConnectorTable.ReplaceErrorChars(item.Key)); attr.InnerText = item.Value?.ToString() ?? ""; node.Attributes.Append(attr); } } if (doc.Children == null) { return; } foreach (var child in doc.Children) { if (child == null) { continue; } child.Name = child.Name.Replace("#", ""); var newNode = docu.CreateNode(XmlNodeType.Element, "Children", ""); Node2XML(child, newNode, docu); node.AppendChild(newNode); } } else { if (data != null) { foreach (var o in data) { var attr = docu.CreateAttribute(o.Key); attr.InnerText = o.Value?.ToString() ?? ""; node.Attributes.Append(attr); } } } }
public static bool DataTableToCSV(ICollection <string> titles, IEnumerable <object[]> datas, char split = ',') { var ofd = new SaveFileDialog { DefaultExt = ".csv", Filter = "Excel格式文件(*.csv)|*.csv" }; string fileName = null; if (ofd.ShowDialog() == true) { fileName = ofd.FileName; } if (fileName == null) { return(false); } FileConnectorTable.DataTableToCSV(titles, datas, fileName, split); return(true); }