我有以下格式的文件中的数据。
HEADER|ReportItem Name: Margin Ri.....
Account Id/Margin Id|Account Name|Ba...... // the row with headers
Data row 1
Data row 2
TRAILER|Record Count: 2
这是抛出一个错误-我相信是因为在实际的reader行之前有一行。
using (var textReader = File.OpenText(path))
{
var csv = new CsvReader(textReader);
csv.Configuration.RegisterClassMap<GsClassMap>();
csv.Configuration.TrimOptions = TrimOptions.Trim;
csv.Configuration.MissingFieldFound = null;
csv.Configuration.Delimiter = "|";
csv.Configuration.HasHeaderRecord = true;
csv.Configuration.ShouldSkipRecord = (x) => x[0].StartsWith("HEADER");
csv.Configuration.ShouldSkipRecord = (x) => x[0].StartsWith("TRAILER");
return csv.GetRecords<GsSma>().ToList();
}
这是抛出一个错误-我相信是因为在实际的reader行之前有一行。
Header matching ['Account Id/Margin Id'] names at index 0 was not found.
如何设置此项以正确读取文件?