public void ReaderAndWriterToCsv(string oldFilePath ,string newFilePath)
{
using (var reader = new StreamReader(oldFilePath))
using (var csv = new CsvReader(reader, CultureInfo.InvariantCulture))
{
//Class1是存放列名的model
var records = csv.GetRecords<Class1>();
List<Class1> templist = new List<Class1>();
foreach (Class1 item in records)
{
if (item.brch_code == "321882" && (DateTime.Parse(item.rcv_time) >= DateTime.Parse("2020-09-15 00:00:00") && DateTime.Parse(item.rcv_time) < DateTime.Parse("2020-09-27 00:00:00")))//筛选条件
{
templist.Add(item);
}
}
using (var writer = new StreamWriter(newFilePath))
using (var csv1 = new CsvWriter(writer, CultureInfo.InvariantCulture))
{
csv1.WriteRecords(templist);
}
}
}
c#读取CSV经过筛选并写入新的CSV
最新推荐文章于 2024-08-19 03:18:07 发布