Csvhelper: Guidance for setting custom header field for a column

Created on 6 Nov 2017  路  7Comments  路  Source: JoshClose/CsvHelper

Looking for guidance on how to handle an issue with column headers.

Issue:
Microsoft Excel registers itself as the default handler for CSV files. There is a known issue within excel, that when the first column of the first row starts with the chars ID, the user will experience an "SYLK: File format is not valid" error message.

Workaround:
To mitigate this, Microsoft's workaround to is to place an apostrophe before the field.

Looking at the documentation for CsvHelper, I seem to be missing how to go about this.

Suggestion:
Ideally, it would be nice if CsvHelper would check for the Display Attribute from System.ComponentModel to get header information. Looking through the source, it looks as though CsvHelper just looks at PropertyName?

Most helpful comment

You can control over the headers. If you want the first header to be ID you can just map it to 'ID instead.

You can either create a map http://joshclose.github.io/CsvHelper/mapping/ or there are attributes you can use that aren't documented yet. [Name("'ID")] They are in namespace CsvHelper.Configuration.Attributes

This should make its way into the documentation 馃槃

All 7 comments

Is this for reading or writing or both?

Writing

You can control over the headers. If you want the first header to be ID you can just map it to 'ID instead.

You can either create a map http://joshclose.github.io/CsvHelper/mapping/ or there are attributes you can use that aren't documented yet. [Name("'ID")] They are in namespace CsvHelper.Configuration.Attributes

Awesome Thanks!

You can control over the headers. If you want the first header to be ID you can just map it to 'ID instead.

You can either create a map http://joshclose.github.io/CsvHelper/mapping/ or there are attributes you can use that aren't documented yet. [Name("'ID")] They are in namespace CsvHelper.Configuration.Attributes

This should make its way into the documentation 馃槃

Was this page helpful?
0 / 5 - 0 ratings