Skip to content

CSV DataReader ge strongly typed data without headers in Excel #125

Answered by MarkPflug
Sushma58 asked this question in Q&A
Discussion options

You must be logged in to vote

There are two ways to accomplish this, by either applying headers to the CSV data, or by adding attributes to the class you are binding to.

Assume you have a class you're binding to that looks like the following:

class MyRecord
{
  public string Name { get; set; }
  public int Value { get; set; }
  public bool IsActive { get; set; }
}

And a CSV file name data.csv containing the following:

a,1,true
b,12,false

Adding headers to CSV.

This allows you to essentially attach the missing header row, and will binding by the column name to the property name.

// create a schema that defines column names that match the target record type.
var schema = Schema.Parse("Name,Value,IsActive");
var opts = new

Replies: 1 comment 1 reply

Comment options

You must be logged in to vote
1 reply
@Sushma58
Comment options

Answer selected by Sushma58
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
2 participants