-
Notifications
You must be signed in to change notification settings - Fork 136
QuickCSVLiteLoad
Cinchoo edited this page Dec 30, 2021
·
2 revisions
To load CSV file, use ChoCSVLiteReader component to parse it. Sample below shows how to load CSV file (Emp.csv)
Id,Name
1,Tom
2,Carl
3,Mark
using (var r = new ChoCSVLiteReader())
{
//Open the reader, skip the header
foreach (var cols in r.ReadFile("emp.csv").Skip(1))
{
Console.WriteLine($"Id: {cols[0]}");
Console.WriteLine($"Name: {cols[1]}");
}
}
using (var r = new ChoCSVLiteReader())
{
//Open the reader, skip the header
var recNum = r.ReadFile("emp.csv").Skip(1).GetEnumerator();
while (recNum.MoveNext())
{
var cols = recNum.Current;
Console.WriteLine($"Id: {cols[0]}");
Console.WriteLine($"Name: {cols[1]}");
}
}
public class Employee
{
public int Id { get; set; }
public string Name { get; set; }
}
foreach (var rec in r.ReadFile<EmployeeRec>("emp.csv", true,
mapper: (lineno, cols, rec) =>
{
rec.Id = cols[0].CastTo<int>();
rec.Name = cols[1];
}))
{
Console.WriteLine($"Id: {rec.Id}");
Console.WriteLine($"Name: {rec.Name}");
}
Please visit below article for detailed walk-through of CSV reader
©2017 Cinchoo Inc