IRONSOFTWAREHOME

C# Read XLSX File

Curtis Chau
Curtis Chau
Updated: August 2, 2026

To read XLSX files in C#, use IronXL's WorkBook.Load method to open Excel files and access worksheets to read cell data, perform calculations, and convert to DataTable or DataSet formats programmatically.

Quickstart: Load a workbook and access a worksheet effortlessly

With IronXL, you can load an XLSX file using the WorkBook.Load method in a single line. Then access its first or named worksheet instantly and begin reading cell values.

  1. 1Install IronXL with NuGet Package Manager

    PM > Install-Package IronXL.Excel

  2. 2Copy and run this code snippet.

    IronXL.WorkBook workbook = IronXL.WorkBook.Load("your-file.xlsx");
    C#
  3. 3Deploy to test on your live environment

    Start using IronXL in your project today with a free trial
    arrow pointer

Read .XLSX Files C#

  • Get IronXL for your project
  • Load a WorkBook
  • Access data from a WorkSheet
  • Apply functions like Sum, Min, & Max
  • Read a WorkSheet as a DataTable, DataSet, and more

How Do I Get IronXL for My Project?

Use IronXL in your project for a simple way to work with Excel file formats in C#. You can either install IronXL via direct download or alternatively you can use NuGet Install for Visual Studio. The software is free for development.

PM > Install-Package IronXL.Excel

Before diving into reading XLSX files, explore the comprehensive IronXL documentation to understand all available features. IronXL supports both .xls and .xlsx formats, making it versatile for legacy and modern Excel files.


How to Tutorial

How Do I Load a WorkBook?

WorkBook is the class of IronXL whose object provides full access to the Excel file and all its functions. For example, to access an Excel file, use the code:

using IronXL;

// Load the workbook
WorkBook workBook = WorkBook.Load("sample.xlsx"); // Excel file path

Why use the WorkBook.Load() method?

In the above code, the Load() function loads WorkBook into WorkBook. Any type of function can be performed on WorkBook by accessing the specific WorkSheet of an Excel file. The Load() method automatically detects the file format, whether it's XLS, XLSX, XLSM, XLTX, or CSV. For more advanced loading scenarios, check out the detailed guide on loading spreadsheets.


How Do I Access a Specific WorkSheet?

To access a specific WorkSheet of an Excel file, IronXL provides the WorkBook class. It can be used in several different ways:

What are the different ways to access a worksheet?

using IronXL;

// Access sheet by name
WorkSheet workSheet = workBook.GetWorkSheet("Sheet1");

WorkBook["SheetName"] is the WorkSheet that is declared in the above portion.

OR

WorkBook

OR

using IronXL;

// Access sheet by index
WorkSheet workSheet = workBook.WorkSheets[0];

OR

WorkBook.Load()

OR

using IronXL;

// Access the default worksheet
WorkSheet workSheet = workBook.DefaultWorkSheet;

OR

sample.xlsx

OR

using IronXL;
using System.Linq;

// Access the first worksheet
WorkSheet workSheet = workBook.WorkSheets.First();

OR

workBook

OR

using IronXL;
using System.Linq;

// Access the first or default worksheet
WorkSheet workSheet = workBook.WorkSheets.FirstOrDefault();

OR

workBook

OR

WorkBook.Load

OR

WorkSheet

OR

WorkSheet

OR

workBook

OR

WorkBook

When should I use each worksheet access method?

Each method has its ideal use case:

  • GetWorkSheet("name"): When you know the exact sheet name
  • WorkSheets[index]: For iterating through sheets programmatically
  • DefaultWorkSheet: Quick access when working with single-sheet files
  • First() or FirstOrDefault(): Safe options when sheet names might change

After getting ExcelSheet workSheet, you can get any type of data from it and perform all Excel functions on it. For more complex worksheet operations, refer to the guide on opening Excel worksheets in C#.


How Do I Access Data from a WorkSheet?

Data can be accessed from ExcelSheet workSheet with this process:

What data types can I read from cells?

using IronXL;

// Accessing data as a string
string dataString = workSheet["A1"].ToString();

// Accessing data as an integer
int dataInt = workSheet["B1"].Int32Value;

IronXL provides various value accessors for different data types:

  • StringValue: For text data
  • Int32Value: For integers
  • DoubleValue: For decimals
  • DateTimeValue: For dates
  • BoolValue: For true/false values

How do I read multiple cells at once?

You can also get data from multiple cells of a specific column:

foreach (var cell in workSheet["A2:A10"])
{
    Console.WriteLine("Value is: {0}", cell.Text);
}

This displays the values from cell A2 to A10. For more advanced range selection techniques, visit the select range tutorial.

What does a complete implementation look like?

A complete code example of the specifics above is provided here:

using IronXL;
using System;

// Load an Excel file
WorkBook workBook = WorkBook.Load("sample.xlsx");
WorkSheet workSheet = workBook.GetWorkSheet("Sheet1");

// Specify the range
foreach (var cell in workSheet["B2:B10"])
{
    Console.WriteLine("Value is: {0}", cell.Text);
}

It displays the following result:

Console output showing extracted worksheet data with Government, Private, Midmarket, and Channel Partners values

With the Excel file Sample.xlsx:

Excel spreadsheet with business data showing Segment, Country, Product, and Discount Band columns across 16 rows

These methodologies show how effortless it is to use Excel file data in your project. For practical examples of reading Excel files without Interop, explore the read Excel examples.


How Can I Perform Functions on Data?

Access filtered data from an Excel WorkSheet by applying aggregate functions like Sum, Min, or Max using the following code:

Which aggregate functions are available?

using IronXL;

// Apply aggregate functions
decimal sum = workSheet["G2:G10"].Sum(); // Sum of cells from G2 to G10
decimal min = workSheet["G2:G10"].Min(); // Minimum value in cells from G2 to G10
decimal max = workSheet["G2:G10"].Max(); // Maximum value in cells from G2 to G10

IronXL supports several aggregate methods you can call directly on a range, including:

  • Avg(): Calculate the mean value
  • Count(): Count non-empty cells
  • Sum(): Add all values
  • Min(): Find the smallest value
  • Max(): Find the largest value

For functions without a dedicated method - such as MEDIAN, COUNTIF, or STDEV - assign the corresponding Excel formula to a cell (for example, cell.Formula = "=MEDIAN(G2:G10)") and let IronXL evaluate it.

How do I implement multiple functions together?

For more details, check out our in-depth tutorial on How to Write C# Excel Files with specifics on aggregate functions. You can also explore the complete list of math functions available in IronXL.

using IronXL;
using System;

// Load the Excel workbook
WorkBook workBook = WorkBook.Load("sample.xlsx");

// Get the specified WorkSheet
WorkSheet workSheet = workBook.GetWorkSheet("Sheet1");

// Calculate sum, minimum, and maximum for a range of cells
decimal sum = workSheet["G2:G10"].Sum();
decimal min = workSheet["G2:G10"].Min();
decimal max = workSheet["G2:G10"].Max();

// Output results
Console.WriteLine("Sum is: {0}", sum);
Console.WriteLine("Min is: {0}", min);
Console.WriteLine("Max is: {0}", max);

This code displays the following output:

Terminal showing data analysis results: Sum=482, Min=12, Max=350 on black background

And this is how the Excel file Sample.xlsx looks:

Excel spreadsheet with sales data showing segments, countries, products, units sold, and pricing across multiple rows

How Do I Read Excel WorkSheet as DataTable?

Using IronXL, it is easy to work with an Excel WorkSheet as a DataTable. This feature is particularly useful when you need to integrate Excel data with existing data processing pipelines or bind data to UI controls.

What is the basic conversion method?

using IronXL;
using System.Data;

// Convert worksheet to DataTable
DataTable dt = workSheet.ToDataTable();

How do I use the first row as column headers?

To use the first row of ExcelSheet as DataTable ColumnName:

using IronXL;
using System.Data;

// Convert worksheet to DataTable with the first row as column names
DataTable dt = workSheet.ToDataTable(true);

The Boolean parameter of ToDataTable() sets the first row as the column names of your DataTable. By default, its value is False. This is especially useful when working with structured data that includes headers.

How do I iterate through the DataTable?

using IronXL;
using System;
using System.Data;

// Load the Excel workbook
WorkBook workBook = WorkBook.Load("sample.xlsx");

// Get the specified WorkSheet
WorkSheet workSheet = workBook.GetWorkSheet("Sheet1");

// Convert WorkSheet to DataTable
DataTable dt = workSheet.ToDataTable(true); // Use first row as column names

// Iterate through rows and columns and display data
foreach (DataRow row in dt.Rows) // Access rows
{
    for (int i = 0; i < dt.Columns.Count; i++) // Access columns of corresponding row
    {
        Console.Write(row[i] + " ");
    }
    Console.WriteLine();
}

Using the above code, every cell value of the WorkSheet can be accessed and used as required. For more advanced DataTable operations, see the guide on importing and exporting as DataSet.


How Do I Read Excel File as DataSet?

IronXL provides a simple function to use a complete Excel file (WorkBook) as a DataSet. Use the ToDataSet method to turn the whole workbook into DataSet.
In this example, we will see how to use the Excel file as a DataSet.

How do I convert a workbook to DataSet?

using IronXL;
using System;
using System.Data;

// Load the Excel workbook
WorkBook workBook = WorkBook.Load("sample.xlsx");

// Convert the WorkBook to a DataSet
DataSet ds = workBook.ToDataSet();

// Iterate through tables in the DataSet and display table names
foreach (DataTable dt in ds.Tables)
{
    Console.WriteLine(dt.TableName);
}

The output of the above code looks like this:

Corrupted or incomplete screenshot showing only Sheet1, Sheet2, Sheet3 labels

And the Excel file Sample.xlsx looks like this:

(center content omitted for brevity)

How do I access each cell value across all worksheets?

In the above example, we can easily parse an Excel file into a DataSet and work with every DataTable of an Excel file as a DataTable. Dive deeper into how to parse Excel as a DataSet here featuring code examples.

Let's see one more example of how to access each cell value of all ExcelSheets. Here, we can access each cell value of every ExcelSheet of an Excel file.

using IronXL;
using System;

// Load the Excel workbook
WorkBook workBook = WorkBook.Load("sample.xlsx");

// Iterate through every WorkSheet in the WorkBook
foreach (WorkSheet workSheet in workBook.WorkSheets)
{
    Console.WriteLine($"Worksheet: {workSheet.Name}");

    // Access each filled cell value on the current WorkSheet
    foreach (var cell in workSheet.FilledCells)
    {
        Console.WriteLine($"{cell.Address}: {cell.Text}");
    }
}
C#

Using the above example, it is convenient to access each cell value of every ExcelSheet of an Excel file. This approach is particularly useful when dealing with multi-sheet workbooks where data is distributed across different tabs.

For more on how to Read Excel Files Without Interop check out the code here. The API reference documentation provides comprehensive details about all available methods and properties at the IronXL API Reference.


Tutorial Quick Access

API Reference for IronXL

Read more about IronXL's features, classes, method fields, namespaces, and enums in the documentation.

API Reference for IronXL

WorkSheet

WorkSheet

WorkSheet

Frequently Asked Questions

How can I read an XLSX file in C# using IronXL?

You can read an XLSX file in C# using IronXL by utilizing the `WorkBook.Load` method, which allows you to open the Excel file and access its worksheets to perform various operations.

What method do I use to access data from a specific worksheet in IronXL?

You can access data from a specific worksheet using several methods like `GetWorkSheet("name")`, `WorkSheets[index]`, `DefaultWorkSheet`, or using LINQ methods such as `First()` or `FirstOrDefault()`.

How do I convert an Excel worksheet to a DataTable using IronXL?

You can convert an Excel worksheet to a DataTable using the `ToDataTable` method, which can use the first row of the worksheet as column headers if specified.

How can I perform aggregate functions like Sum, Min, and Max with IronXL?

IronXL allows you to perform aggregate functions such as `Sum()`, `Min()`, and `Max()` directly on a range of cells, facilitating easy data analysis.

What are the benefits of using IronXL to read XLSX files in C#?

IronXL provides a simple API for reading XLSX files in C#, supporting a wide range of Excel formats and allowing for data manipulation and conversion without needing Excel Interop.

How do I handle different data types when accessing cell values with IronXL?

IronXL offers specific value accessors for different data types, like `StringValue` for text, `Int32Value` for integers, `DoubleValue` for decimals, and `DateTimeValue` for dates.

Can I convert an entire workbook to a DataSet with IronXL?

Yes, you can convert an entire workbook to a DataSet using the `ToDataSet` method, which allows you to work with each worksheet as a separate DataTable.

What is the recommended way to read multiple cells at once in IronXL?

You can read multiple cells by iterating over a specified range, for example, using `foreach` on `workSheet["A2:A10"]` to read each cell's value.

How do I install IronXL in my C# project?

You can install IronXL via direct download or through NuGet Package Manager in Visual Studio. The library is free for development purposes.

How can I display Excel sheet data results in the console using IronXL?

To display Excel sheet data in the console, load the workbook using `WorkBook.Load`, access the desired worksheet, and iterate through cells to output their values using `Console.WriteLine`.

Curtis Chau
Technical Writer

Curtis Chau holds a Bachelor’s degree in Computer Science (Carleton University) and specializes in front-end development with expertise in Node.js, TypeScript, JavaScript, and React. Passionate about crafting intuitive and aesthetically pleasing user interfaces, Curtis enjoys working with modern frameworks and creating well-structured, visually appealing manuals.

...
Read More

Ready to Get Started?

Nuget Downloads 2,237,574Version:2026.9just released

Get your free 30-day Trial Key instantly.
No credit card or account creation required
C# NuGet Library for PDF
Install with NuGet

Version: 2026.9

PM > Install-Package IronXL.Excel
nuget.org/packages/IronXL.Excel/
  1. In Solution Explorer, right-click References, Manage NuGet Packages
  2. Select Browse and search "IronXL"
  3. Select the package and install
C# PDF DLL
Download DLL

Version: 2026.9

  1. Download and unzip IronXL to a location such as ~/Libs within your Solution directory
  2. In Visual Studio Solution Explorer, right click References. Select Browse, "IronXL.dll"

Licenses from $999

Key in blue circle

Get your free 30-day Trial Key instantly.

Your trial license will be sent to your email address

No limitations. 100% unlocked. No credit card.

bullet_checkedNo credit card or account creation requiredNo limitations. 100% unlocked. No credit card.
  • Logo Aetna
  • Logo NASA
  • Logo GE
  • Logo Porsche
  • Logo USDA
  • Logo Qatar
Join Millions of Engineers who’ve tried IronPDF
Book your free Live Demo
Booking Badge

Trusted by Millions of Engineers Worldwide

Iron Software's customer logos
Get Your No-Obligation Consult
Complete the form below or email sales@ironsoftware.com
Your details will always be kept confidential.
Trusted by Millions of Engineers Worldwide
Iron Software's customer logos
Get your free 30-day Trial Key instantly.
No credit card or account creation required