欢迎您访问程序员文章站本站旨在为大家提供分享程序员计算机编程知识!
您现在的位置是: 首页  >  数据库

.net CsvHelper 2.0

程序员文章站 2022-03-16 10:29:38
...

http://joshclose.github.io/CsvHelper/ var outputmatchPath = System.Configuration.ConfigurationManager.AppSettings[//FilePath]; TextReader requiredMatchElementsfileReader = File.OpenText(outputmatchPath); var matchCsv = new CsvReader(requir

http://joshclose.github.io/CsvHelper/



var outputmatchPath = System.Configuration.ConfigurationManager.AppSettings["//FilePath"];

TextReader requiredMatchElementsfileReader = File.OpenText(outputmatchPath);

var matchCsv = new CsvReader(requiredMatchElementsfileReader);


matchCsv.Configuration.RegisterClassMapRequiredMatchElementsMap>();
var requiredMatchList = matchCsv.GetRecordsRequiredMatchElements>().ToList();



public class RequiredMatchElements
{
public int IngredientId { set; get; }


public string IngredientName { set; get; }


public string RequriedElementsString { set; get; }
}


public class RequiredMatchElementsMap : CsvClassMap
{
public override void CreateMap()
{
Map(m => m.IngredientId).Name("IngredientId");
Map(m => m.IngredientName).Name("IngredientName");
Map(m => m.RequriedElementsString).Name("RequriedElementsString");
}


}


Write




using (TextWriter streamWriter =
new StreamWriter(HttpContext.Current.Server.MapPath("/App_Data/Top5000Instagram.csv")))
{


var csv = new CsvWriter(streamWriter);
csv.WriteRecords(dateList);
}