Writing data into CSV file in C#

后端 未结 15 1351
清酒与你
清酒与你 2020-11-22 17:15

I am trying to write into a csv file row by row using C# language. Here is my function

string first = reader[0].ToString();
string second=image.         


        
15条回答
  •  被撕碎了的回忆
    2020-11-22 17:33

    Here is another open source library to create CSV file easily, Cinchoo ETL

    List objs = new List();
    
    dynamic rec1 = new ExpandoObject();
    rec1.Id = 10;
    rec1.Name = @"Mark";
    rec1.JoinedDate = new DateTime(2001, 2, 2);
    rec1.IsActive = true;
    rec1.Salary = new ChoCurrency(100000);
    objs.Add(rec1);
    
    dynamic rec2 = new ExpandoObject();
    rec2.Id = 200;
    rec2.Name = "Tom";
    rec2.JoinedDate = new DateTime(1990, 10, 23);
    rec2.IsActive = false;
    rec2.Salary = new ChoCurrency(150000);
    objs.Add(rec2);
    
    using (var parser = new ChoCSVWriter("emp.csv").WithFirstLineHeader())
    {
        parser.Write(objs);
    }
    

    For more information, please read the CodeProject article on usage.

提交回复
热议问题