C# Open Excel Worksheets with IronXL
Open Excel worksheets in C# using IronXL's WorkBook.Load() and GetWorkSheet() methods to access any Excel file type (.xls, .csv, .tsv, .xlsx) and read or manipulate data with just two lines of code.
Learn how to use C# to open Excel worksheet functions for working with Excel spreadsheets and all file types including .xls, .csv, .tsv, and .xlsx. Opening an Excel worksheet, reading its data, and manipulating it programmatically are essential for many business applications. IronXL provides a streamlined approach that eliminates the need for Excel Interop, offering a solution 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. IronXL makes it simple to start reading or editing data immediately.
Get started making PDFs with NuGet now:
Install IronXL with NuGet Package Manager
Copy and run this code snippet.
WorkBook wb = WorkBook.Load("sample.xlsx"); WorkSheet ws = wb.GetWorkSheet("Sheet1");Deploy to test on your live environment
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
Step 1
How Do I Access the 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#. For detailed installation instructions and system requirements, consult the IronXL documentation.
Install-Package IronXL.Excel
IronXL supports deployment across multiple platforms including Linux, macOS, and Docker containers, making it versatile for various development environments.
How to Tutorial
How Do I Load an 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. IronXL supports loading various spreadsheet formats including XLS, XLSX, CSV, TSV, and more. For comprehensive guidance on loading different file types, see the load spreadsheet tutorial.
:path=/static-assets/excel/content-code-examples/how-to/c-sharp-open-excel-worksheet-load-workbook.csusing IronXL;
// Get a worksheet by its name
WorkSheet workSheet = workBook.GetWorkSheet("SheetName");IRON VB CONVERTER ERROR developers@ironsoftware.comThe Excel file at the specified path will load into the workBook object. Now, specify the Excel worksheet to open. The WorkBookLoadOptions parameter allows you to handle password-protected workbooks and control formula recalculation behavior.
How Do I Open an Excel WorkSheet?
To open a specific WorkSheet of an Excel file, IronXL provides the WorkBook.GetWorkSheet() function. Use it to 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")The specified WorkSheet will open in workSheet with all its data. There are several 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.csusing 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()For more advanced worksheet management tasks like adding, renaming, or deleting worksheets, refer to the manage worksheet guide.
Now, get data from the opened Excel WorkSheet.
How Do I Get Data from a WorkSheet?
Get data from an opened Excel WorkSheet in the following ways:
- Get a specific cell value of Excel
WorkSheet. - Get data in a specific Range.
- Get all the data from
WorkSheet. - Export data to other formats.
Let's examine how to get data in different ways with these examples:
How Do I Get Specific Cell Values?
The first approach to getting data from an Excel WorkSheet is to get specific cell values. Access them 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()workSheet is the WorkSheet of the Excel file, as shown 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()Here's an example of how to open an Excel file in your 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.csusing 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)This code displays the following output:
Value of Excel file sample.xlsx in row [3].Column [1] and C6 cell:
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. For more examples on reading Excel files, check out the how to read Excel file tutorial.
How Do I Get Data from a Specific Range?
Now examine how to get data in a specific range from an opened Excel WorkSheet using IronXL. The select range functionality provides powerful options for data extraction.
IronXL provides an intelligent way to get data in a specific range. 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")Here's an example of using 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.csusing 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.comThe above code will pull data from B2 to B10 as follows:
The values of the Excel file sample.xlsx, from B2 to B10:
How Do I Get Data from a Row?
You 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.csvar rowData = workSheet["A1:E1"];IRON VB CONVERTER ERROR developers@ironsoftware.comThis will display all values from A1 to E1. Read more about C# Excel Ranges and how to work with different row and column identifications.
How Do I Get All Data from a WorkSheet?
Getting all the cell data from the open Excel WorkSheet is easy using IronXL. For this task, access each cell value by row and column indexes. You can also export the entire worksheet to various formats like CSV, JSON, or XML for easier processing. See the following example, which traverses all WorkSheet cells and accesses their values.
In this example, two loops work together: one traverses each row of the Excel WorkSheet and the other traverses each column of a specific row. This way, each cell value is easily accessed.
:path=/static-assets/excel/content-code-examples/how-to/c-sharp-open-excel-worksheet-all.csusing 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 iThe output of the above code will display each cell value of the complete open Excel WorkSheet. For working with larger datasets, consider using IronXL's DataSet and DataTable export functionality for better performance and memory management.
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 ResourceFrequently Asked Questions
How do I open an Excel worksheet in C# without Microsoft Office installed?
IronXL provides a simple solution using WorkBook.Load() and GetWorkSheet() methods. With just two lines of code, you can open any Excel file (.xls, .xlsx, .csv, .tsv) without requiring Excel Interop or Microsoft Office installation on your system.
What file formats are supported when opening Excel worksheets?
IronXL supports multiple spreadsheet formats including .xls (older Excel format), .xlsx (modern Excel format), .csv (comma-separated values), and .tsv (tab-separated values). The WorkBook.Load() function automatically handles all these formats seamlessly.
Can I deploy my Excel worksheet application on Linux or macOS?
Yes, IronXL supports cross-platform deployment including Linux, macOS, and Docker containers. This makes it versatile for various development environments beyond Windows, eliminating platform-specific limitations.
How do I install the Excel C# library for my project?
You can access IronXL through a DLL download or install it via NuGet package manager. The library provides comprehensive documentation for detailed installation instructions and system requirements to get started quickly.
What's the basic code to load an Excel file and access a specific worksheet?
Simply use two lines: WorkBook wb = WorkBook.Load("sample.xlsx"); WorkSheet ws = wb.GetWorkSheet("Sheet1"); This loads your Excel file and opens the named worksheet for immediate data access and manipulation.










