请在 csvhelper 上快速帮助...
csv:姓名,姓氏
人物地图:
public override void CreateMap()
{
Map(x => x.Name).Name("Name");
Map(x => x.LasName).Name("LastName");
}
人物类:
public string Name { get; set; }
public string LastName { get; set; }
主要的:
public void writePerson()
{
IEnumerable<Person> records;
using (var r = new CsvReader(new StreamReader("person.csv")))
{
r.Configuration.RegisterClassMap<PersonMap>();
records = r.GetRecords<Person>().ToList();
}
using (var w = new CsvWriter(new StreamWriter("person.csv")))
{
w.Configuration.RegisterClassMap<PersonMap>();
w.WriteRecord(records); //rewrite csv list
w.WriteField("John"));
w.WriteField("Doe");
w.NextRecord();
}
}
错误行:记录 = reader.GetRecords().ToList();
错误:未找到标头记录。