exportcontactstocvs.cs

来自「破解的飞信源代码」· CS 代码 · 共 62 行

CS
62
字号
namespace Imps.Client.Pc
{
    using System;
    using System.IO;
    using System.Text;
    using System.Windows.Forms;
    using System.Xml;

    internal class ExportContactsToCVS : IExportContacts
    {
        public void ExportContacts(IWin32Window owner, string filePath, string xmlContacts)
        {
            XmlDocument document = new XmlDocument();
            document.LoadXml(xmlContacts);
            if (document.DocumentElement.ChildNodes.Count != 0)
            {
                StringBuilder builder = new StringBuilder();
                for (int i = 0; i < document.DocumentElement.ChildNodes[0].ChildNodes.Count; i++)
                {
                    builder.Append(string.Format("\"{0}\"", document.DocumentElement.ChildNodes[0].ChildNodes[i].Name));
                    if (i != (document.DocumentElement.ChildNodes[0].ChildNodes.Count - 1))
                    {
                        builder.Append(",");
                    }
                    else
                    {
                        builder.Append("\r\n");
                    }
                }
                foreach (XmlNode node in document.DocumentElement.ChildNodes)
                {
                    for (int j = 0; j < node.ChildNodes.Count; j++)
                    {
                        builder.Append(string.Format("\"{0}\"", node.ChildNodes[j].InnerText));
                        if ((node.ChildNodes.Count - 1) != j)
                        {
                            builder.Append(",");
                        }
                        else
                        {
                            builder.Append("\r\n");
                        }
                    }
                }
                using (StreamWriter writer = new StreamWriter(filePath, false, ImportExportManager.FileEncoding))
                {
                    writer.Write(builder.ToString());
                }
            }
        }

        public string Filter
        {
            get
            {
                return "csv files (*.csv)|*.csv";
            }
        }
    }
}

⌨️ 快捷键说明

复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?