Replies: 1 comment 2 replies
-
All Excel functionality was removed, except for injection sanitization. You should be able to do it fairly easily by creating your own parser. void Main()
{
var s = new StringBuilder();
s.AppendLine("Id,Name");
s.AppendLine("=01,one");
s.AppendLine("=02,two");
using (var reader = new StringReader(s.ToString()))
using (var parser = new ExcelParser(reader, CultureInfo.InvariantCulture))
using (var csv = new CsvReader(parser))
{
csv.GetRecords<Foo>().ToList().Dump();
}
}
public class Foo
{
public int Id { get; set; }
public string Name { get; set; }
}
public class ExcelParser : CsvParser
{
public ExcelParser(TextReader textReader, CultureInfo culture) : base(textReader, culture) { }
public override string[] Read()
{
var row = base.Read();
if (row == null)
{
return row;
}
for (var i = 0; i < row.Length; i++)
{
row[i] = row[i].TrimStart('=');
}
return row;
}
} |
Beta Was this translation helpful? Give feedback.
2 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Uh oh!
There was an error while loading. Please reload this page.
-
Hey all
I have used CSVhelper a bunch of times and love it. I have some applications where they are "helpfully" including the excel fix of "=" as a preamble to quoted 0 filled numerics to prevent the Excel interpreter from eating the leading 0. CSVhelper reports this row as an error. Other than search/replace to pull the "=" out, is there a way to tell CSVhelper to ignore this equals and process successfully? I see options for including = in the written output but not to allow them in the parse. Thanks
Beta Was this translation helpful? Give feedback.
All reactions