public LniDataTable(string filePath) { TableName = Path.GetFileNameWithoutExtension(filePath); List <string> sectionList = LniUtils.ReadAllSection(filePath); foreach (var s in sectionList) { IdObjectMap.Add(s, new LniObject(filePath, s)); } }
public void SaveOut(string path) { //--第一行是要取出的数据-- CsvStreamReader reader = CsvStreamReader.CreateReader(OutPutFile, Encoding.GetEncoding("UTF-8")); List <string> dataFilterList = new List <string>(); dataFilterList.Add(IDLabel); for (int i = 1; i <= reader.ColCount; i++) { string data = reader[1, i]; dataFilterList.Add(data); } List <InfoObject> table = new List <InfoObject>(); List <string> sectionList = LniUtils.ReadAllSection(FilePath); foreach (var section in sectionList) { List <string> datas = new List <string>(); foreach (var dataFilter in dataFilterList) { if (dataFilter == IDLabel) { datas.Add(section); } else { //引号会丢失...貌似没问题? string value = INIHelper.ReadString(section, dataFilter, "", FilePath); datas.Add(value); } //Console.WriteLine(value); } table.Add(new InfoObject(section, datas)); } StringBuilder csv = new StringBuilder(); foreach (var f in dataFilterList) { csv.Append(f); csv.Append(","); } csv = csv.Remove(csv.Length - 1, 1);//最后的逗号 csv.AppendLine(); foreach (var infoObject in table) { csv.AppendLine(infoObject.GetCsv()); } File.WriteAllText(path, csv.ToString()); }