首頁  >  文章  >  資料庫  >  .net CsvHelper 2.0

.net CsvHelper 2.0

WBOY
WBOY原創
2016-06-07 15:44:271540瀏覽

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);
            }





陳述:
本文內容由網友自願投稿,版權歸原作者所有。本站不承擔相應的法律責任。如發現涉嫌抄襲或侵權的內容,請聯絡admin@php.cn