Which .NET library is for reading manipulating and writing Excel?

Easily import data from common data sources, like arrays, data tables, collection objects, and HTML tables, into an Excel worksheet.

Which .NET library is for reading manipulating and writing Excel?

Export data

Data in an existing worksheet can also be exported to data tables, collection objects, and nested classes.

Which .NET library is for reading manipulating and writing Excel?

Sorting

Data sorting can be performed based on cell value, cell color, and font color using multiple sorting algorithms.

Which .NET library is for reading manipulating and writing Excel?

Filters

Excel Library supports various filter options like top, top10, and percent, with different filter types such as custom, combination, dynamic, color, icon, and advanced filters.

Which .NET library is for reading manipulating and writing Excel?

Data validation

Cell data validations can be applied with operators, alert messages, custom formulas, and dropdown lists.

Last modified: April 07, 2022

  • Create a MVC application
  • Install the Closed_XML package

Which .NET library is for reading manipulating and writing Excel?

private ClosedXML.Excel.XLWorkbook GenerateClosedXMLWorkbook() { var wb = new ClosedXML.Excel.XLWorkbook(); var ws = wb.AddWorksheet(); ws.FirstCell().SetValue("Hello world!"); ws.FirstCell().CellBelow().FormulaA1 = "RAND()"; return wb; }
Save
string path = "C:\\Temp\\Excel\\"; if (!Directory.Exists(path)) { Directory.CreateDirectory(path); } using (var wb = GenerateClosedXMLWorkbook()) { wb.SaveAs(path + "test.xlsx"); }
Download
using (var wb = GenerateClosedXMLWorkbook()) { return wb.Deliver("generatedfile.xlsx"); }
Read
var dt = new DataTable(); dt.Columns.Add("Col1"); var filePath = "C:\\Temp\\Excel\\test.xlsx"; using (var workBook = new XLWorkbook(filePath)) { var workSheet = workBook.Worksheet(1); foreach (IXLRow row in workSheet.Rows()) { int i = 0; dt.Rows.Add(); foreach (IXLCell cell in row.Cells()) { dt.Rows[dt.Rows.Count - 1][i] = cell.Value.ToString(); i++; } } }


Get $100 Free, sign up today

Which .NET library is for reading manipulating and writing Excel?

ClosedXML is a .NET library for reading, manipulating and writing Excel 2007+ (.xlsx, .xlsm) files. It aims to provide an intuitive and user-friendly interface to dealing with the underlying OpenXML API.

For more information see the documentation or the wiki.

Release notes & migration guide

The public API is still not stable and it is a very good idea to read release notes and migration guide before each update.

  • Release notes for 0.100
  • Migration guide for 0.100
  • Release notes for 0.97

Frequent answers

  • If you get an exception Unable to find font font name or fallback font fallback font name. Install missing fonts or specify a different fallback font through ‘LoadOptions.DefaultGraphicEngine = new DefaultGraphicEngine(“Fallback font name”)’, see help page about missing fonts.
  • ClosedXML is not thread-safe. There is no guarantee that parallel operations will work. The underlying OpenXML library is also not thread-safe.
  • If you get an exception The type initializer for 'Gdip' threw an exception. on Linux, you have to upgrade to 0.97+.

Install ClosedXML via NuGet

If you want to include ClosedXML in your project, you can install it directly from NuGet

To install ClosedXML, run the following command in the Package Manager Console

PM> Install-Package ClosedXML

What can you do with this?

ClosedXML allows you to create Excel files without the Excel application. The typical example is creating Excel reports on a web server.

Example:

using (var workbook = new XLWorkbook())
{
    var worksheet = workbook.Worksheets.Add("Sample Sheet");
    worksheet.Cell("A1").Value = "Hello World!";
    worksheet.Cell("A2").FormulaA1 = "=MID(A1, 7, 5)";
    workbook.SaveAs("HelloWorld.xlsx");
}

Extensions

Be sure to check out our ClosedXML extension projects

  • https://github.com/ClosedXML/ClosedXML.Report
  • https://github.com/ClosedXML/ClosedXML.Extensions.AspNet
  • https://github.com/ClosedXML/ClosedXML.Extensions.Mvc
  • https://github.com/ClosedXML/ClosedXML.Extensions.WebApi

Developer guidelines

The OpenXML specification is a large and complicated beast. In order for ClosedXML, the wrapper around OpenXML, to support all the features, we rely on community contributions. Before opening an issue to request a new feature, we'd like to urge you to try to implement it yourself and log a pull request.

Which library is used for working with Excel?

Openpyxl is a Python library that is used to read from an Excel file or write to an Excel file. Data scientists use Openpyxl for data analysis, data copying, data mining, drawing charts, styling sheets, adding formulas, and more.

How to read an Excel file in C#?

How to Read Excel File in C#.
Download the C# Library to read Excel files..
Load and read an Excel file (workbook).
Create an Excel workbook in CSV or XLSX..
Edit cell values in a range of cells..
Validate spreadsheet data..
Export data using Entity Framework..

What is Excelpackage C#?

Represents an Excel 2007/2010 XLSX file package. This is the top-level object to access all parts of the document.