Sylvan.Data.Excel 0.4.28

Prefix Reserved
There is a newer version of this package available.
See the version list below for details.
dotnet add package Sylvan.Data.Excel --version 0.4.28
                    
NuGet\Install-Package Sylvan.Data.Excel -Version 0.4.28
                    
This command is intended to be used within the Package Manager Console in Visual Studio, as it uses the NuGet module's version of Install-Package.
<PackageReference Include="Sylvan.Data.Excel" Version="0.4.28" />
                    
For projects that support PackageReference, copy this XML node into the project file to reference the package.
<PackageVersion Include="Sylvan.Data.Excel" Version="0.4.28" />
                    
Directory.Packages.props
<PackageReference Include="Sylvan.Data.Excel" />
                    
Project file
For projects that support Central Package Management (CPM), copy this XML node into the solution Directory.Packages.props file to version the package.
paket add Sylvan.Data.Excel --version 0.4.28
                    
#r "nuget: Sylvan.Data.Excel, 0.4.28"
                    
#r directive can be used in F# Interactive and Polyglot Notebooks. Copy this into the interactive tool or source code of the script to reference the package.
#:package Sylvan.Data.Excel@0.4.28
                    
#:package directive can be used in C# file-based apps starting in .NET 10 preview 4. Copy this into a .cs file before any lines of code to reference the package.
#addin nuget:?package=Sylvan.Data.Excel&version=0.4.28
                    
Install as a Cake Addin
#tool nuget:?package=Sylvan.Data.Excel&version=0.4.28
                    
Install as a Cake Tool

Sylvan.Data.Excel

A cross-platform .NET library for reading and writing Excel data files. The most commonly used formats: .xlsx, .xlsb and .xls, are supported for reading, while .xlsx and .xlsb formats are supported for writing.

ExcelDataReader provides readonly, row by row, forward-only access to the data. It provides a familiar API via DbDataReader, which is ideal for accessing rectangular, tabular data sets. It exposes a single, unified API for accessing all supported file formats.

ExcelDataWriter supports writing data from a DbDataReader to an Excel worksheet in .xlsx and .xlsb formats. ExcelDataWriter can only write a new Excel, it cannot be used to edit or append to existing files. It does not support custom formatting, charts, or other common features. It is meant only to export raw, flat data to Excel.

The library is a purely managed implementation with no external dependencies.

This library is currently the fastest and lowest allocating library for reading Excel data files in the .NET ecosystem, for all supported formats.

If you encounter any issues while using this library, please report an issue in the github repository. Be aware that I will be unlikely to investigate any issue unless an example file can be provided reproducing the issue.

Installing

Sylvan.Data.Excel Nuget Package

Install-Package Sylvan.Data.Excel

ExcelDataReader

ExcelDataReader derives from DbDataReader, so it exposes an API that should be familiar for anyone who has worked with ADO.NET before. The field accessors allow reading data in an efficient, strongly-typed manner: GetString, GetInt32, GetDateTime, GetBoolean, etc.

The GetExcelDataType method allows inspecting the native Excel data type of a cell, which may vary from row to row. FieldCount, returns the number of columns in the header row, and doesn't change while processing each row in a sheet. RowFieldCount returns the number of fields in the current row, which might vary from row to row, and can be used to access cells in a "jagged", non-rectangular file.

Reading Raw Data

The ExcelDataReader provides a forward only, row by row access to the data in a worksheet. It allows iterating over sheets using the NextResult() method, and iterating over rows using the Read() method. Fields are accessed using standard accessors, most commonly GetString(). GetString() is designed to not throw an exception, except in the case that a cell contains a formula error. The TryOpenWorksheet(string name) method can be used to open a specific, known worksheet.

using Sylvan.Data.Excel;

// ExcelDataReader derives from System.Data.DbDataReader
// The Create method can open .xls, .xlsx or .xlsb files.
using ExcelDataReader edr = ExcelDataReader.Create("data.xls");

do 
{
	var sheetName = edr.WorksheetName;
	// enumerate rows in current sheet.
	while(edr.Read())
	{
		// iterate cells in row.
		// can use edr.RowFieldCount when sheet contains jagged, non-rectangular data
		for(int i = 0; i < edr.FieldCount; i++)
		{
			var value = edr.GetString(i);
		}
		// Can use other strongly-typed accessors
		// bool flag = edr.GetBoolean(0);
		// DateTime date = edr.GetDateTime(1);
		// decimal amt = edr.GetDecimal(2);
	}
	// iterates sheets
} while(edr.NextResult());

Bind Excel data to objects using Sylvan.Data

The Sylvan.Data library includes a general-purpose data binder that can bind a DbDataReader to objects. This can be used to easily read an Excel file as a series of strongly typed objects.

using Sylvan.Data;
using Sylvan.Data.Excel;

using var edr = ExcelDataReader.Create("data.xlsx");
foreach (MyRecord item in edr.GetRecords<MyRecord>())
{
    Console.WriteLine($"{item.Name} {item.Quantity}");
}

class MyRecord
{
    public int Id { get; set; }
    public string Name { get; set; }
    public int? Quantity { get; set; }
    public DateTime Date { get; set; }
}

Converting Excel data to CSV(s)

The Sylvan.Data.Csv library can be used to convert Excel worksheet data to CSV.

using Sylvan.Data.Excel;
using Sylvan.Data.Csv;

using var edr = ExcelDataReader.Create("data.xlsx");

do 
{
	var sheetName = edr.WorksheetName;
	using CsvDataWriter cdw = CsvDataWriter.Create("data-" + sheetName + ".csv")
	cdw.Write(edr);
} while(edr.NextResult());

ExcelDataWriter

The ExcelDataWriter type is used to create Excel workbooks and write DbDataReader data as worksheets.

// *critical* to dispose (using) ExcelDataWriter.
using var edw = ExcelDataWriter.Create("data.xlsx");
DbDataReader dr;
dr = GetQueryResults("UserReport");
edw.Write(dr, "UserReport");
dr = GetQueryResults("SecurityAudit");
edw.Write(dr, "SecurityAudit");
Product Compatible and additional computed target framework versions.
.NET net6.0 is compatible.  net6.0-android was computed.  net6.0-ios was computed.  net6.0-maccatalyst was computed.  net6.0-macos was computed.  net6.0-tvos was computed.  net6.0-windows was computed.  net7.0 was computed.  net7.0-android was computed.  net7.0-ios was computed.  net7.0-maccatalyst was computed.  net7.0-macos was computed.  net7.0-tvos was computed.  net7.0-windows was computed.  net8.0 was computed.  net8.0-android was computed.  net8.0-browser was computed.  net8.0-ios was computed.  net8.0-maccatalyst was computed.  net8.0-macos was computed.  net8.0-tvos was computed.  net8.0-windows was computed.  net9.0 was computed.  net9.0-android was computed.  net9.0-browser was computed.  net9.0-ios was computed.  net9.0-maccatalyst was computed.  net9.0-macos was computed.  net9.0-tvos was computed.  net9.0-windows was computed.  net10.0 was computed.  net10.0-android was computed.  net10.0-browser was computed.  net10.0-ios was computed.  net10.0-maccatalyst was computed.  net10.0-macos was computed.  net10.0-tvos was computed.  net10.0-windows was computed. 
Compatible target framework(s)
Included target framework(s) (in package)
Learn more about Target Frameworks and .NET Standard.
  • net6.0

    • No dependencies.

NuGet packages (4)

Showing the top 4 NuGet packages that depend on Sylvan.Data.Excel:

Package Downloads
GreatUtilities.Infrastructure

Essencial tools to agile development.

Verify.Sylvan.Data.Excel

Extends Verify (https://github.com/VerifyTests/Verify) to allow verification via Sylvan.Data.Excel https://github.com/MarkPflug/Sylvan.Data.Excel/

Purcell

一个超高性能的Excel强类型读写映射库。(支持.xls .xlsx .csv)

Sylvan.AspNetCore.Mvc.Excel

Package Description

GitHub repositories

This package is not used by any popular GitHub repositories.

Version Downloads Last Updated
0.5.2 16,649 11/7/2025
0.5.1 8,988 10/17/2025
0.5.0 11,332 9/19/2025
0.4.30 13,632 8/20/2025
0.4.29 8,485 7/23/2025
0.4.28 1,809 7/23/2025
0.4.27 31,793 6/27/2025
0.4.26 30,429 5/5/2025
0.4.26-b0001 7,640 12/3/2024
0.4.25 222,575 8/15/2024
0.4.25-b0001 200 8/14/2024
0.4.24 37,742 6/21/2024
0.4.23 9,913 6/3/2024
0.4.22 11,195 5/13/2024
0.4.21 1,136 5/5/2024
0.4.20 2,266 4/25/2024
0.4.20-b0001 477 4/1/2024
0.4.19 62,108 11/29/2023
0.4.18 5,669 11/16/2023
0.4.17 10,775 9/26/2023
0.4.17-b0004 229 9/22/2023
0.4.17-b0003 245 9/15/2023
0.4.17-b0002 410 9/12/2023
0.4.17-b0001 239 9/11/2023
0.4.16 8,260 9/8/2023
0.4.15 809 9/5/2023
0.4.14 30,161 8/17/2023
0.4.13 4,700 7/19/2023
0.4.13-b0001 292 7/12/2023
0.4.12 16,219 5/18/2023
0.4.11 6,906 4/25/2023
0.4.10 4,782 3/28/2023
0.4.9 3,434 3/3/2023
0.4.8 112,351 2/23/2023
0.4.7 1,704 2/22/2023
0.4.6 1,561 2/16/2023
0.4.6-b0001 299 2/10/2023
0.4.5 3,458 1/28/2023
0.4.4 2,191 1/18/2023
0.4.3 51,517 12/7/2022
0.4.2 1,402 11/25/2022
0.4.1 1,120 11/17/2022
0.4.0 8,452 11/2/2022
0.3.4 1,254 11/2/2022
0.3.3 7,566 9/12/2022
0.3.2 1,349 9/2/2022
0.3.1 1,765 9/1/2022
0.3.0 1,670 8/12/2022
0.2.3 1,031 8/10/2022
0.2.2 963 8/9/2022
0.2.1 1,300 7/18/2022
0.2.0 1,855 6/24/2022
0.2.0-b0004 344 6/23/2022
0.2.0-b0003 350 6/22/2022
0.2.0-b0002 364 6/21/2022
0.2.0-b0001 380 6/18/2022
0.1.12 1,071 6/16/2022
0.1.11 1,039 6/15/2022
0.1.11-b0006 380 6/6/2022
0.1.11-b0005 2,264 5/10/2022
0.1.11-b0004 359 5/2/2022
0.1.11-b0003 404 3/8/2022
0.1.11-b0002 368 2/28/2022
0.1.11-b0001 341 2/23/2022
0.1.10 5,067 2/22/2022
0.1.9 1,023 2/21/2022
0.1.8 1,029 2/20/2022
0.1.7 1,123 1/22/2022
0.1.6 1,896 1/13/2022
0.1.4 2,175 11/28/2021
0.1.3 929 10/18/2021
0.1.2 994 10/8/2021
0.1.1 939 10/5/2021
0.1.0 1,183 10/4/2021