jehugaleahsa / FlatFiles

Reads and writes CSV, fixed-length and other flat file formats with a focus on schema definition, configuration and speed.
The Unlicense
357 stars 64 forks source link

Handling this Excel CSV format #16

Closed ghost closed 8 years ago

ghost commented 8 years ago

Some CSV files I get have the syntax:

..., ="12345", ...

The "=" is used force Excel to treat the number as a string when it loads the file. I know that I could pre-process the file to remove all the "=", but I'm interested in seeing what would be involved in modifying FlatFiles to handle that case

jehugaleahsa commented 8 years ago

This gave me an idea. I made the changes necessary to associate a preprocessor Func with a column. Then you could handle your situation like this:

mapper.Property(x => x.SomeValue).Preprocessor(x => x.Trim('"', '='));

Before the value is parsed (to an int or decimal), the preprocessor in the example above would remove any leading or trailing quotes (") or equal signs (=).

I created a unit test for you to use as an example: https://github.com/jehugaleahsa/FlatFiles/blob/master/test/FlatFiles.Test/PreprocessorTester.cs#L13.

ghost commented 8 years ago

Perfect!