Csvhelper: HasExcelSeparator is missing

Created on 16 Nov 2017  路  5Comments  路  Source: JoshClose/CsvHelper

i am using csvHelper version 6.0.0 , i could not found 'HasExcelSeparator','TrimFields' properties which are accessable in 'configuration' Class.how can i access these above mentioned properties .Got Stuck..Thanks in Advance.

All 5 comments

All the Excel specific stuff was removed, so HasExcelSeparator doesn't exist anymore. Excel stuff will need to come from a contrib library or another place.

TrimFields is now done using TrimOptions.

Does this mean that you can no longer read csv files with an excel seperator line?

So, if this is not supported anymore, is there anywhere an example how to achieve compatibility with the most used CSV viewer on this world?

sep=, would imply Excel wrote the file.

You can add the functionality back in with 1 line of code.

csv.Configuration.Delimiter = Regex.Match(reader.ReadLine(), "sep=(.*)").Groups[1].Value;

Full example:

void Main()
{
    var s = new StringBuilder();
    s.AppendLine("sep=,");
    s.AppendLine("Id,Name");
    s.AppendLine("1,one");
    using (var reader = new StringReader(s.ToString()))
    using (var csv = new CsvReader(reader, CultureInfo.InvariantCulture))
    {
        csv.Configuration.Delimiter = Regex.Match(reader.ReadLine(), "sep=(.*)").Groups[1].Value;       
        csv.GetRecords<Foo>().ToList().Dump();
    }
}

public class Foo
{
    public int Id { get; set; }
    public string Name { get; set; }
}

Thank you!

Was this page helpful?
0 / 5 - 0 ratings