Read CSV with ExcelDataReader
How ExcelDataReader reads CSV files in .NET: what the CSV reader does, encoding and separator caveats, and when a dedicated CSV parser is the better choice.
ExcelDataReader is an open-source .NET library best known for reading legacy .xls and modern .xlsx workbooks. It also includes a CSV reader that exposes delimited text through the same IExcelDataReader interface used for spreadsheets. This review covers what that CSV path does to your data, where it holds up, and where a dedicated CSV parser or plain text handling is the better fit.
Short verdict
ExcelDataReader suits CSV import when your application already reads Excel files and you want one code path for workbooks and delimited text. The main benefit is consistency: CSV rows arrive through the same row-by-row reader or DataSet conversion as spreadsheet rows. The main tradeoff is that the library only reads. It does not write CSV, it does not map rows to typed classes, and it hands back cell values as text that you convert yourself. If your project only handles CSV, needs strongly typed records, or must write files back out, a dedicated CSV library such as CsvHelper is usually the more direct choice. If you only need to inspect or lightly edit a file, plain text tools are simpler still.
What the CSV reader actually changes
Reading a CSV with ExcelDataReader does not modify the file. The library parses the bytes into rows and fields in memory. Nothing is reversed, restyled or reformatted, and because CSV carries no fonts, colors or cell formats, there is no presentation layer to preserve or lose. The only transformations are the ones every CSV parser makes: decoding bytes into characters, splitting lines into fields at the separator, and removing the quotes that wrap fields containing separators or line breaks.
Three behaviors matter most in practice:
- Opening: CSV must be opened explicitly with ExcelReaderFactory.CreateCsvReader. The general CreateReader method detects binary and Open XML workbook formats and is not meant for plain delimited text.
- Encoding: the reader looks for a byte order mark. When none is present, it uses the FallbackEncoding from ExcelReaderConfiguration. The documented default is the Windows-1252 code page, which on .NET Core and later requires registering CodePagesEncodingProvider before use.
- Separators and analysis: the reader picks a separator from the AutodetectSeparators list, and by default it analyzes the entire file to settle encoding, separator and field count before you read rows. AnalyzeInitialCsvRows limits that analysis to a set number of rows, at the cost of the RowCount property no longer being available.
Minimal example
The snippet below reads a CSV row by row. It assumes the ExcelDataReader package is installed; the commented DataSet conversion additionally needs the ExcelDataReader.DataSet package. Check the configuration property names against the version you install, since options have been added across releases.
using System.Text;
using ExcelDataReader;
// Required on .NET Core and later for code-page fallback encodings
Encoding.RegisterProvider(CodePagesEncodingProvider.Instance);
using var stream = File.Open("data.csv", FileMode.Open, FileAccess.Read);
using var reader = ExcelReaderFactory.CreateCsvReader(stream, new ExcelReaderConfiguration
{
FallbackEncoding = Encoding.UTF8,
AutodetectSeparators = new[] { ',', ';', '\t' }
});
while (reader.Read())
{
for (int i = 0; i < reader.FieldCount; i++)
{
var value = reader.GetValue(i); // CSV values arrive as text
}
}
// Or, with ExcelDataReader.DataSet:
// var result = reader.AsDataSet(new ExcelDataSetConfiguration
// {
// ConfigureDataTable = _ => new ExcelDataTableConfiguration { UseHeaderRow = true }
// });
Does the data keep its meaning and stay usable?
Because CSV values come back as text rather than inferred numbers or dates, ExcelDataReader avoids a common problem with opening CSV in a spreadsheet application: leading zeros in codes, long numeric identifiers and date-like strings are not silently reinterpreted. The flip side is that every type conversion is your responsibility. Parse numbers and dates with an explicit culture, especially when files come from regions that use a comma as the decimal mark and a semicolon as the separator.
Most practical failures trace back to encoding and separator guessing rather than to parsing itself:
- Files without a byte order mark are decoded with the fallback encoding. If that does not match how the file was saved, accented letters and non-Latin scripts turn into garbled characters. Set FallbackEncoding to match your sources; UTF-8 is the safer choice for most modern exports.
- Separator detection is a heuristic. Single-column files, or files where a candidate separator appears inside unquoted text, can be split incorrectly. If your sources always use one delimiter, restrict AutodetectSeparators to that single character.
- Rows with fewer fields than the widest row still need defensive handling. Check for null or empty values instead of assuming every column is populated.
- Full-file analysis means large files are read through before the first row is returned. For large inputs, measure whether AnalyzeInitialCsvRows helps in your environment.
Since ExcelDataReader is a library running inside your own process, the parsed data stays in your application's memory. What happens to it afterward, including how it is displayed to users or exposed to assistive technology, depends entirely on your own interface, not on the reader.
When plain text or another tool is preferable
- Choose ExcelDataReader when you already import xls or xlsx and want CSV handled through the same reader and DataSet pipeline.
- Choose a dedicated CSV parser when you need typed record mapping, fine control over quoting and escaping, or the ability to write CSV.
- Use plain text handling when the goal is to view, search or hand-edit a file, or when the file is simple enough that splitting lines is clearly safe. Even then, quoted fields with embedded commas or line breaks are a reason to switch to a real parser.
Evidence gaps
This review relies on the library's documented behavior and general CSV principles. No performance benchmarks, memory measurements or side-by-side tests against other parsers were available, so no speed or resource claims are made here. Behavior on edge cases such as quoted fields spanning several lines, mixed line endings or unusual encodings should be confirmed with a scoped test against your own sample files and the specific library version you deploy.