// READ SPREADSHEETS WITH C#

ExcelDataReader — read Excel files with C#

A lightweight .NET library for reading spreadsheet data.

ExcelDataReader is a fast, open-source C# library that reads .xls, .xlsx, .xlsb and .csv files from a stream in your .NET application. It reads data — it is not Excel, a workbook editor, or an online converter. This is an independent guide.

// WORKBOOK.XLSX · SHEET1 NameDateAmountAct Ada2026-011240Y Lin2026-02980N Rao2026-021515Y Mir2026-03640Y … ExcelReader Factory using var reader = ExcelReaderFactory .CreateReader(stream); while (reader.Read()) { var name = reader.GetString(0); var amt = reader.GetValue(2); } // typed C# values .XLSX .CSV

01 / SNAPSHOT

What you need to know at a glance

PRODUCT

C#/.NET file reader library

INSTALL

NuGet package in a .NET project

INPUTS

XLS · XLSX · XLSB · CSV

OUTPUT

Row reader or DataSet extension

THE BASICS

What is ExcelDataReader?

A .NET library is reusable code you add to a project with a NuGet package. ExcelDataReader reads a workbook from a Stream — it doesn’t open Microsoft Excel.

File streamtrusted source ReaderFactoryCreateReader WorksheetsNextResult() RowsRead() Values/ DataSet

Reads from a stream

Point ExcelReaderFactory.CreateReader(stream) at a file stream and iterate rows with an IExcelDataReader. No Excel install is needed for server-side parsing (verify any caveats for your runtime).

Reader vs DataSet

Iterate row-by-row for low memory, or add the ExcelDataReader.DataSet package to materialise a whole DataSet with AsDataSet().

What it does not do

No workbook authoring, no formula engine, no charts, no online conversion, and no spreadsheets hosted by this website. It reads data; your code does the rest.

SPEC SHEET

Package / project information

Substantiated details only. Confirm the current version and frameworks on NuGet before you publish.

NameExcelDataReader
Category.NET / C# Excel & CSV reader
Base packageExcelDataReader
ExtensionExcelDataReader.DataSet
EcosystemNuGet
Core APIExcelReaderFactory · IExcelDataReader
FormatsXLS · XLSX · XLSB · CSV
LicenseMIT (verify on NuGet)
Latest stable (verify)3.9.0
Latest prerelease4.0.0-beta1

INSTALL

Get ExcelDataReader — install via NuGet

You add a package dependency to a .NET project — there’s no standalone installer. Every link points to the official NuGet and GitHub pages.

dotnet cli

# .NET CLI — base reader packagedotnet add package ExcelDataReader --version 3.9.0 # Only if you use AsDataSet()dotnet add package ExcelDataReader.DataSet --version 3.9.0

Reconfirm 3.9.0 on NuGet before publishing.

visual studio

// Package Manager Console (Visual Studio)Install-Package ExcelDataReaderInstall-Package ExcelDataReader.DataSet <!-- or PackageReference in your .csproj --><PackageReference Include="ExcelDataReader" Version="3.9.0" />

Use the NuGet Package Manager UI or edit the .csproj directly.

Install the base ExcelDataReader package for low-level reading. AsDataSet() lives in the separate ExcelDataReader.DataSet package — installing only the base package won’t give you that method.

CAPABILITIES

Key capabilities

Grounded in the package documentation — not marketing claims.

 

Read workbooks and CSV from a stream

Open .xlsx, legacy .xls and .xlsb with CreateReader, and CSV with CreateCsvReader. Walk sheets and rows with a low-level reader, or materialise a DataSet with the companion package.

while (reader.Read()) { /* row */ }
reader.NextResult(); // next sheet

Modern & legacy Excel

Read .xlsx and older .xls through one factory API.

Dedicated CSV reader

CreateCsvReader handles delimiters and encoding; cells come back as strings.

Row & sheet navigation

Iterate with Read() and move between worksheets with NextResult().

Optional DataSet

Add ExcelDataReader.DataSet for AsDataSet() and header-row handling.

Configurable reading

Header-row treatment, CSV delimiter/encoding and stream behaviour where supported.

PIPELINE

How ExcelDataReader works

A conceptual data flow — from a trusted stream to typed values in your own models.

1 · Stream in

Your app opens a trusted local or uploaded file as a Stream and keeps it in a using block.

2 · Factory opens it

ExcelReaderFactory.CreateReader(stream) (or CreateCsvReader) returns an IExcelDataReader for the format.

3 · Iterate sheets & rows

Loop sheets with NextResult() and rows with Read(), reading cells by index.

4 · Read values safely

Get values with GetValue / typed getters, handling nulls and type mismatches your own way.

5 · Map to your models

Project rows into your classes or database — or materialise a DataSet when the extension is installed. Dispose the reader and stream when done.

FORMATS

Supported Excel and CSV formats

“Excel file” covers several formats. Support depends on the package version — verify for your release.

.XLSX

supported

Modern Excel

The Open XML workbook format used by current Excel versions.

.XLS

supported

Legacy Excel

Older BIFF workbooks; may need code-page registration on .NET Core.

.XLSB

supported

Binary workbook

Excel’s binary format, where supported by your version.

.CSV

supported

Plain text

Read with CreateCsvReader; values are strings — you convert types.

Historical formats can have different encoding behaviour, and CSV is plain text (mind the separator, BOM and encoding). .xml SpreadsheetML and .ods support is version-specific — confirm before relying on it. Sample tiles show educational values only, never real data.

DEFENSIVE CODE

Safe spreadsheet ingestion

ExcelDataReader reads files — it does not sanitise malicious documents or enforce your security controls. That’s your application’s job.

01

Expected sources only

Accept files from sources your application expects, not arbitrary public uploads.

02

Validate server-side

Check size, type and business rules on the server — a file extension is not validation.

03

Treat content as untrusted

Cell values, paths and metadata are user input; never trust them blindly.

04

Set resource limits

Cap time and memory for large or malformed files; streaming uses less than AsDataSet().

05

Don’t log sensitive cells

Keep workbook contents and any credentials out of logs and error messages.

06

Handle bad files

Catch exceptions for corrupt, unsupported or password-protected workbooks gracefully.

07

Sanitize before use

Validate values before DB writes or HTML output; mind CSV injection on export paths.

08

Clean up temp files

Dispose streams/readers and delete temporary uploads per your app’s requirements.

SETUP

How to install in .NET / Visual Studio

A beginner-friendly path. Confirm your SDK and target framework against the current NuGet listing.

create & add

// 1. A compatible .NET project (console app shown)dotnet new console -n ExcelReaderDemocd ExcelReaderDemo // 2. Add the package(s)dotnet add package ExcelDataReader --version 3.9.0// add ExcelDataReader.DataSet only if you use AsDataSet()

usings & encoding

// 3. Usingsusing System.IO;using ExcelDataReader; // 4. Register code pages ONLY for older .xls on .NET Core / .NET 5+System.Text.Encoding.RegisterProvider(    System.Text.CodePagesEncodingProvider.Instance);

The code-pages provider needs the System.Text.Encoding.CodePages package.

QUICKSTART

C# quickstart & real code

A low-level reader example. Verify it compiles for your target framework and C# language version.

Program.cs

using System;using System.IO;using ExcelDataReader; var path = "sample.xlsx"; // local fileusing var stream = File.Open(path, FileMode.Open, FileAccess.Read);using var reader = ExcelReaderFactory.CreateReader(stream); do{    Console.WriteLine($"Sheet: {reader.Name}");    while (reader.Read())    {        for (int c = 0; c < reader.FieldCount; c++)            Console.WriteLine(reader.GetValue(c));    }}while (reader.NextResult());

Iterates every sheet and prints each cell. Requires a local sample.xlsx.

Line by line

  • CreateReader(stream) opens the workbook.
  • the outer do…while (NextResult()) walks each worksheet.
  • reader.Read() advances one row at a time.
  • FieldCount is the column count; GetValue(c) reads a cell.
  • using disposes the stream and reader for you.

DEEP DIVE

DataSet, CSV, configuration & advanced usage

Use the right tool for the job — and install ExcelDataReader.DataSet before calling AsDataSet().

AsDataSet()

using ExcelDataReader;// needs the ExcelDataReader.DataSet package using var reader = ExcelReaderFactory.CreateReader(stream);var result = reader.AsDataSet(new ExcelDataSetConfiguration{    ConfigureDataTable = _ => new ExcelDataTableConfiguration    {        UseHeaderRow = true    }});// result.Tables[0] is your first sheet

UseHeaderRow treats the first row as column names.

CSV reader

using ExcelDataReader; // CSV: dedicated factory methodusing var stream = File.Open("data.csv",    FileMode.Open, FileAccess.Read);using var reader =    ExcelReaderFactory.CreateCsvReader(stream); while (reader.Read())    Console.WriteLine(reader.GetString(0)); // CSV cells are strings

Convert numbers/dates yourself; CSV values are text.

Large files

Process row-by-row with the reader to keep memory low. AsDataSet() loads everything into memory, so it costs more on big workbooks.

Data types

Use GetValue, check IsDBNull, and guard typed getters against InvalidCastException. There’s no automatic model binding.

Legacy .xls

Register CodePagesEncodingProvider on .NET Core / .NET 5+ for older code-page encodings. Behaviour varies by framework.

CHOOSE

ExcelDataReader vs other approaches

Pick by use case, not by invented benchmarks. Verify each library’s current features and license before deciding.

Reading

ExcelDataReader

  • ModelLow-level row reader
  • Writes?No — reading only
  • Formatsxls, xlsx, xlsb, csv
  • Best forFast import pipelines
  • LicenseMIT (verify)

Read + write

ClosedXML

  • ModelWorkbook object model
  • Writes?Yes
  • Formatsxlsx (not legacy xls)
  • Best forCreating/editing xlsx
  • LicenseMIT (verify)

Read + write

EPPlus

  • ModelWorkbook object model
  • Writes?Yes
  • Formatsxlsx
  • Best forRich xlsx generation
  • LicensePolyform/commercial — verify

Low-level

Open XML SDK

  • ModelRaw Open XML parts
  • Writes?Yes
  • Formatsxlsx (Open XML)
  • Best forFull control of xlsx
  • LicenseMIT (verify)

If you only need to read rows quickly, ExcelDataReader is a strong fit; if you must create or edit workbooks, a workbook-object library suits better. Confirm licensing for your use — some alternatives have commercial terms.

REALITY

Performance, security & limitations

Memory

Row-by-row reading is light; AsDataSet() holds the whole workbook in memory, so large files cost more. Measure for your data — we don’t publish invented throughput numbers.

Edge cases

Legacy encodings, corrupt workbooks, unexpected cell types and password-protected files are real-world cases to handle with try/catch and validation.

Disposal

Streams and readers need correct disposal (using) and exception handling, or you’ll hit ObjectDisposedException and leaks.

This website

This guide does not receive or process your spreadsheets, and can’t promise package security, maintainer support or Microsoft endorsement. No library is inherently safe against malicious input.

FIXES

Troubleshooting — common C# problems

Symptom → likely cause → safe fix. Exact exception text and behaviour can vary by version.

ExcelReaderFactory / namespace not found

The package isn’t installed or the using is missing. Add the NuGet package and `using ExcelDataReader;`.

AsDataSet() is missing

AsDataSet lives in ExcelDataReader.DataSet — install that companion package too.

FileNotFoundException

Wrong relative path or permissions. Use a correct absolute/relative path and check file access.

Unreadable / corrupt / unsupported file

Confirm the format is supported for your version and the file isn’t damaged; handle the exception.

NotSupportedException: encoding 1252

Register CodePagesEncodingProvider on .NET Core / .NET 5+ for legacy .xls.

CSV delimiter / encoding wrong

Set the correct encoding and separator; remember CSV cells are strings.

Numbers come back as strings (CSV)

Expected for CSV — convert with int.Parse / decimal.Parse etc. in your code.

Header row read as data

Use ExcelDataReader.DataSet with UseHeaderRow = true, or skip the first Read().

InvalidCastException from Get*()

The cell type differs from the getter. Use GetValue and convert, or check IsDBNull.

Only the first sheet is read

Loop with NextResult() to move to the next worksheet.

AsDataSet() uses too much memory

Switch to row-by-row reading for large workbooks instead of materialising a DataSet.

ObjectDisposedException

The stream or reader was disposed/closed too early — keep them in scope while reading.

Framework / NuGet restore conflicts

Match the package to a supported target framework and run dotnet restore.

Password-protected workbook

Encrypted/protected files may be unsupported; handle the failure and document the limitation.

Expecting to write Excel

ExcelDataReader reads only — use a workbook-writing library to create or edit files.

FAQ

Frequently asked questions

ExcelDataReader is a lightweight, open-source C#/.NET library for reading spreadsheet files — .xls, .xlsx, .xlsb and .csv — from a stream. It reads data; it doesn’t write or edit workbooks.

Yes. It’s developed in the open on GitHub under an MIT license (verify the exact license on the current NuGet/GitHub pages).

No. It parses files directly, so Microsoft Excel generally doesn’t need to be installed for server-side reading. Verify any caveats for your runtime.

Run dotnet add package ExcelDataReader (and ExcelDataReader.DataSet if you use AsDataSet()), use the Visual Studio NuGet Manager, or add a PackageReference to your .csproj.

The base ExcelDataReader package gives you the low-level reader API. ExcelDataReader.DataSet is a separate package that adds the AsDataSet() extension for materialising a DataSet.

Open the file as a stream and call ExcelReaderFactory.CreateReader(stream); the same API handles both modern .xlsx and legacy .xls. Then iterate rows with Read().

It reads .xlsb where supported by your version, and reads CSV via ExcelReaderFactory.CreateCsvReader(stream). CSV cell values are returned as strings.

No. ExcelDataReader only reads. To create or edit workbooks, use a workbook-writing library such as ClosedXML, EPPlus or the Open XML SDK.

Install ExcelDataReader.DataSet and call reader.AsDataSet(…), optionally with ExcelDataSetConfiguration and UseHeaderRow = true to treat the first row as headers.

On .NET Core / .NET 5+, register System.Text.CodePagesEncodingProvider.Instance (from the System.Text.Encoding.CodePages package) before reading older .xls files.

Read row-by-row to keep memory low; AsDataSet() loads the whole workbook into memory. Always validate and set resource limits for untrusted uploads in your own app.

No. exceldatareader.com is an independent educational guide. The official source, packages and docs are on GitHub and NuGet, maintained by the upstream project.

// FROM ROWS TO USABLE DATA

From spreadsheet rows to clean C# data.

Add ExcelDataReader to your .NET project, open a workbook from a stream, and read rows into your own models — no Excel install required.

exceldatareader.com is an independent documentation resource, not the official project or a Microsoft product. Always verify versions and APIs against NuGet and GitHub.

Scroll to Top