【问题标题】:CSV Helper first row been skippedCSV Helper 第一行被跳过
【发布时间】:2021-03-30 16:56:28
【问题描述】:

我正在使用 CSV Helper 读取 CSV 文件但第一行被跳过,我看到它可以是配置但我看不到如何强制读取第一行。

有什么想法吗?

try
{
    using var csv = new CsvReader(file);
    var records = csv.GetRecords<TMap>().ToList();
    return _mapper.Map<List<T>>(records.ToList());
}
catch (Exception e)
{
    throw new Exception($"Error parsing the Csv File. Error: {e.Message}");
}

【问题讨论】:

    标签: asp.net csvhelper


    【解决方案1】:

    您需要先设置配置。

    试试这个

    var config = new CsvConfiguration(CultureInfo.InvariantCulture)
    {
        HasHeaderRecord = true,
    };
    try
    {
    
        using var csv = new CsvReader(file, config);
    
        var records = csv.GetRecords<TMap>().ToList();
        return _mapper.Map<List<T>>(records.ToList());
    }
    catch (Exception e)
    {
        throw new Exception($"Error parsing the Csv File. Error: {e.Message}");
    }
    
    
    

    【讨论】:

    • 我会努力回来的。感谢您的快速回复。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2014-07-16
    • 2019-01-01
    • 2022-11-15
    • 2015-09-18
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多