C# Open Excel Worksheets

This article was translated from English: Does it need improvement?
Translated
View the article in English

Learn how to use C# to open Excel Worksheet functions to work with Excel Spreadsheets and open all file types including (.xls, .csv, .tsv, and .xlsx). Opening an Excel Worksheet, reading its data, and manipulating it programmatically are essential for many developing applications. Here's a solution for every developer who wants a method with fewer lines of code and faster response times.

Quickstart: Load a Workbook and Open a Worksheet in One Line

Just two simple method calls let you load any supported Excel file and open a named worksheet—no complex setup or interop required. It’s an easy get-started path using IronXL so you can start reading or editing data immediately.

Nuget IconGet started making PDFs with NuGet now:

  1. Install IronXL with NuGet Package Manager

    PM > Install-Package IronXL.Excel

  2. Copy and run this code snippet.

    WorkBook wb = WorkBook.Load("sample.xlsx"); WorkSheet ws = wb.GetWorkSheet("Sheet1");
  3. Deploy to test on your live environment

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

Minimal Workflow (5 Steps)

  • Install C# library to open Excel files
  • Load the Excel file into WorkBook object
  • Explore many ways to select WorkSheet from the opened Excel file
  • Access cell data via the selected WorkSheet object
  • Get data from rows and columns range
How To Work related to C# Open Excel Worksheets

Step 1

1. Access Excel C# Library

Access the Excel C# Library via DLL or install it using your preferred NuGet manager. Once you've accessed the IronXL library and added it to your project, you can use all the functions below to open Excel Worksheets in C#.

Install-Package IronXL.Excel

How to Tutorial

2. Load Excel File

Use the WorkBook.Load() function from IronXL to load Excel files into the project. This function requires a string parameter, which is the path of the Excel file to be opened. See here:

:path=/static-assets/excel/content-code-examples/how-to/c-sharp-open-excel-worksheet-load-workbook.cs
using IronXL;

// Get a worksheet by its name
WorkSheet workSheet = workBook.GetWorkSheet("SheetName");
IRON VB CONVERTER ERROR developers@ironsoftware.com
$vbLabelText   $csharpLabel

The Excel file at the specified path will load into the workBook object. Now, we need to specify the Excel Worksheet which will be opened.


3. Open Excel WorkSheet

To open a specific WorkSheet of an Excel file, IronXL provides the WorkBook.GetWorkSheet() function. Using this, we can easily open the Worksheet by its name:

:path=/static-assets/excel/content-code-examples/how-to/c-sharp-open-excel-worksheet-get-worksheet.cs
// Get a worksheet by its name
WorkSheet workSheet = workBook.GetWorkSheet("SheetName");
' Get a worksheet by its name
Dim workSheet As WorkSheet = workBook.GetWorkSheet("SheetName")
$vbLabelText   $csharpLabel

The specified WorkSheet will open in workSheet with all its data. There are also a few other ways to open a specific WorkSheet of an Excel file:

:path=/static-assets/excel/content-code-examples/how-to/c-sharp-open-excel-worksheet-multiple-open.cs
using IronXL;
using System.Linq;

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

// Open the default worksheet
WorkSheet workSheet2 = workBook.DefaultWorkSheet;

// Open the first sheet
WorkSheet workSheet3 = workBook.WorkSheets.First();

// Open the first or default sheet
WorkSheet workSheet4 = workBook.WorkSheets.FirstOrDefault();
Imports IronXL
Imports System.Linq

' Open by sheet index
Private workSheet As WorkSheet = workBook.WorkSheets(0)

' Open the default worksheet
Private workSheet2 As WorkSheet = workBook.DefaultWorkSheet

' Open the first sheet
Private workSheet3 As WorkSheet = workBook.WorkSheets.First()

' Open the first or default sheet
Private workSheet4 As WorkSheet = workBook.WorkSheets.FirstOrDefault()
$vbLabelText   $csharpLabel

Now, we just need to get data from the opened Excel WorkSheet.


4. Get Data from WorkSheet

We can get data from an opened Excel WorkSheet in the following ways:

  1. Get a specific cell value of Excel WorkSheet.
  2. Get data in a specific Range.
  3. Get all the data from WorkSheet.

Let's see one by one how to get data in different ways with these examples:

4.1. Get Specific Cell Value

The first approach to getting data from an Excel WorkSheet is to get the specific cell values. It can be accessed like this:

:path=/static-assets/excel/content-code-examples/how-to/c-sharp-open-excel-worksheet-cell-address.cs
// Access a specific cell value by its address
string val = workSheet["Cell Address"].ToString();
' Access a specific cell value by its address
Dim val As String = workSheet("Cell Address").ToString()
$vbLabelText   $csharpLabel

workSheet is the WorkSheet of the Excel file, as we will see in the following examples. Specific cell values can also be accessed by specifying "row index" and "column index."

:path=/static-assets/excel/content-code-examples/how-to/c-sharp-open-excel-worksheet-cell-row.cs
// Access a cell value by row index and column index
string val = workSheet.Rows[RowIndex].Columns[ColumnIndex].Value.ToString();
' Access a cell value by row index and column index
Dim val As String = workSheet.Rows(RowIndex).Columns(ColumnIndex).Value.ToString()
$vbLabelText   $csharpLabel

Let's see an example of how to open an Excel file in our C# project and get specific cell values using both methods:

:path=/static-assets/excel/content-code-examples/how-to/c-sharp-open-excel-worksheet-specified-cell.cs
using IronXL;
using System;

WorkBook workBook = WorkBook.Load("sample.xlsx");

// Open WorkSheet
WorkSheet workSheet = workBook.GetWorkSheet("Sheet1");

// Get value By Cell Address
int intValue = workSheet["C6"].Int32Value;

// Get value by Row and Column Address
string strValue = workSheet.Rows[3].Columns[1].Value.ToString();

Console.WriteLine("Getting Value by Cell Address: {0}", intValue);
Console.WriteLine("Getting Value by Row and Column Indexes: {0}", strValue);
Imports IronXL
Imports System

Private workBook As WorkBook = WorkBook.Load("sample.xlsx")

' Open WorkSheet
Private workSheet As WorkSheet = workBook.GetWorkSheet("Sheet1")

' Get value By Cell Address
Private intValue As Integer = workSheet("C6").Int32Value

' Get value by Row and Column Address
Private strValue As String = workSheet.Rows(3).Columns(1).Value.ToString()

Console.WriteLine("Getting Value by Cell Address: {0}", intValue)
Console.WriteLine("Getting Value by Row and Column Indexes: {0}", strValue)
$vbLabelText   $csharpLabel

This code displays the following output:

1output related to 4.1. Get Specific Cell Value

Value of Excel file sample.xlsx in row [3].Column [1] and C6 cell:

1excel related to 4.1. Get Specific Cell Value

The rows and column indices start from 0.

Open Excel WorkSheets and get specific cell data, and you can read more about how to read Excel data in C# from already open Excel Worksheets.

4.2. Get Data from Specific Range

Now let's see how to get data in a specific range from an opened Excel WorkSheet using IronXL.

IronXL provides an intelligent way to get data in a specific range. We just specify from to to values:

:path=/static-assets/excel/content-code-examples/how-to/c-sharp-open-excel-worksheet-select-range.cs
// Access data from a specific range
var rangeData = workSheet["From Cell Address : To Cell Address"];
' Access data from a specific range
Dim rangeData = workSheet("From Cell Address : To Cell Address")
$vbLabelText   $csharpLabel

Let's see an example of how to use range to get data from an open Excel WorkSheet:

:path=/static-assets/excel/content-code-examples/how-to/c-sharp-open-excel-worksheet-from-range.cs
using IronXL;
using System;

// Load 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);
}
IRON VB CONVERTER ERROR developers@ironsoftware.com
$vbLabelText   $csharpLabel

The above code will pull data from B2 to B10 as follows:

2output related to 4.2. Get Data from Specific Range

We can see the values of the Excel file sample.xlsx, from B2 to B10:

2excel related to 4.2. Get Data from Specific Range

4.3. Get Data from Row

We can also describe a range for a specific row. For example:

:path=/static-assets/excel/content-code-examples/how-to/c-sharp-open-excel-worksheet-select-row-range.cs
var rowData = workSheet["A1:E1"];
IRON VB CONVERTER ERROR developers@ironsoftware.com
$vbLabelText   $csharpLabel

This will display all values from A1 to E1. Read more about C# Excel Ranges and how to work with different row and column identifications.

4.4. Get All Data from WorkSheet

Getting all the cell data from the open Excel WorkSheet is also easy using IronXL. For this task, we need to access each cell value by row and column indexes. Let's see the following example, in which we will traverse all WorkSheet cells and access its values.

In this example, basically, two loops are working: one is for traversing each row of Excel WorkSheet and the other is for traversing each column of a specific row. In this way, each cell value can be easily accessed.

:path=/static-assets/excel/content-code-examples/how-to/c-sharp-open-excel-worksheet-all.cs
using IronXL;
using System;
using System.Linq;

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

// Access all rows of the open Excel WorkSheet
for (int i = 0; i < workSheet.Rows.Count(); i++)
{
    // Access all columns of a specific row
    for (int j = 0; j < workSheet.Columns.Count(); j++)
    {
        // Access each cell for the specified column
        Console.WriteLine(workSheet.Rows[i].Columns[j].Value.ToString());
    }
}
Imports IronXL
Imports System
Imports System.Linq

' Load Excel file
Private workBook As WorkBook = WorkBook.Load("sample2.xlsx")
Private workSheet As WorkSheet = workBook.GetWorkSheet("Sheet1")

' Access all rows of the open Excel WorkSheet
For i As Integer = 0 To workSheet.Rows.Count() - 1
	' Access all columns of a specific row
	For j As Integer = 0 To workSheet.Columns.Count() - 1
		' Access each cell for the specified column
		Console.WriteLine(workSheet.Rows(i).Columns(j).Value.ToString())
	Next j
Next i
$vbLabelText   $csharpLabel

The output of the above code will display each cell value of the complete open Excel WorkSheet.


Tutorial Quick Access

Documentation related to Tutorial Quick Access

API Reference Resource

Use the IronXL API Reference resource as your guide to all functions and classes for use in your projects, as well as namespaces, method fields, enums, and feature sets.

API Reference Resource

Preguntas Frecuentes

¿Cómo puedo abrir y manipular hojas de cálculo de Excel usando C#?

Puede abrir y manipular hojas de cálculo de Excel en C# utilizando la biblioteca IronXL. Comience instalando la biblioteca, luego cargue su archivo de Excel en un objeto WorkBook usando WorkBook.Load(). Puede seleccionar y abrir hojas de cálculo específicas con el método WorkBook.GetWorkSheet().

¿Qué tipos de archivos de Excel son soportados en C#?

En C#, puede trabajar con varios tipos de archivos de Excel como .xls, .csv, .tsv y .xlsx usando la biblioteca IronXL.

¿Cómo puedo recuperar el valor de una celda específica de una hoja de cálculo de Excel en C#?

Para recuperar el valor de una celda específica de una hoja de cálculo de Excel utilizando C#, utilice la biblioteca IronXL para acceder a las celdas por su dirección con ws["Cell Address"].ToString() o especificando índices de fila y columna usando ws.Rows[RowIndex].Columns[ColumnIndex].Value.ToString().

¿Puedo obtener datos de un rango definido de celdas en una hoja de cálculo usando C#?

Sí, puede obtener datos de un rango definido de celdas en una hoja de cálculo usando C# empleando la sintaxis de la biblioteca IronXL ws["From Cell Address : To Cell Address"] para acceder a los datos dentro del rango especificado.

¿Cómo puedo leer todos los datos de una hoja de cálculo de Excel programáticamente?

Para leer todos los datos de una hoja de cálculo de Excel programáticamente en C#, puede recorrer cada fila y columna usando la biblioteca IronXL, accediendo al valor de cada celda con ws.Rows[i].Columns[j].Value.ToString().

¿Por qué deberían los desarrolladores usar una biblioteca para manejar archivos de Excel en C#?

Usar una biblioteca como IronXL es beneficioso para los desarrolladores ya que simplifica el proceso de abrir, leer y manipular archivos de Excel dentro de proyectos de C#, proporcionando funciones y clases robustas para manejar el contenido de Excel de manera eficiente.

¿Cómo puedo instalar una biblioteca para manejar Excel en mi proyecto de C#?

Para instalar la biblioteca IronXL para manejar Excel en su proyecto de C#, use el administrador de paquetes NuGet con el comando dotnet add package IronXL.Excel.

¿Es posible abrir una hoja de cálculo por su índice en un libro de trabajo usando C#?

Sí, puedes abrir una hoja de cálculo por su índice en un libro de trabajo usando la biblioteca IronXL con la sintaxis WorkSheet ws = wb.WorkSheets[index];, donde 'index' representa la posición de la hoja de cálculo en el libro de trabajo.

¿Cómo puedo trabajar con rangos específicos de celdas en un archivo de Excel usando C#?

IronXL le permite trabajar con rangos específicos de celdas especificando rangos como "A1:E1" para acceder y manipular los datos dentro de ese rango definido en un archivo de Excel.

¿Dónde puedo encontrar más información sobre las funciones disponibles para manejar Excel en C#?

Para obtener información más detallada sobre las funciones disponibles para manejar Excel en C#, puede consultar el recurso de referencia de la API de IronXL, que proporciona documentación completa sobre funciones, clases y espacios de nombres. Visite la referencia de la API en https://ironsoftware.com/csharp/excel/object-reference/api/.

Curtis Chau
Escritor Técnico

Curtis Chau tiene una licenciatura en Ciencias de la Computación (Carleton University) y se especializa en el desarrollo front-end con experiencia en Node.js, TypeScript, JavaScript y React. Apasionado por crear interfaces de usuario intuitivas y estéticamente agradables, disfruta trabajando con frameworks modernos y creando manuales bien ...

Leer más
¿Listo para empezar?
Nuget Descargas 1,686,155 | Versión: 2025.11 recién lanzado