Test in production without watermarks.
Works wherever you need it to.
Get 30 days of fully functional product.
Have it up and running in minutes.
Full access to our support engineering team during your product trial
This article will discuss how you can read Excel data in C# using IronXL, a lightweight and fast library that is one of the most widely used C# libraries to interact with Excel files.
IronXL is a C# library that allows developers to easily read, write, and manipulate Excel files without the need for Microsoft Excel to be installed on the machine. It is a powerful tool for working with Excel data or reading Excel files in C# and provides a simple and easy-to-use API for reading and writing Excel files.
IronXL is a C# Excel library that provides a wide range of features or Excel functionality for working with Excel data, including:
IronXL can read, write, and manipulate Excel files in a variety of formats, including XLS, XLSX, CSV, and XML. It also supports reading of password-protected Excel files and other advanced operations.
IronXL provides support for working with Excel charts, allowing developers to create and manipulate charts within Excel files.
IronXL provides support for saving and exporting Excel files in different formats.
IronXL supports various file formats, such as XLS, XLSX, CSV, and XML.
IronXL provides support for working with Excel formulas, allowing developers to calculate formulas within Excel files.
IronXL provides support for working with Excel cell styling, allowing developers to format Excel files professionally.
This tutorial will create a project using the C# programming language and Visual Studio 2019.
Creating a C# Console Application in Visual Studio
Choose a name for the new C# Console Application Project
For best results, choose the latest available version of the .NET Framework for your C# Console Project
Existing C# projects can also be used. Simply open the project and add the library. The following section will show how to install the Excel library IronXL.
There are two methods for downloading and installing the IronXL library:
Access the NuGet Package Manager Console by going to Tools > NuGet Package Manager** > Package Manager Console
In the Console, type the following command and press Enter.
Install-Package IronXL.Excel
Install-Package IronXL.Excel
The IronXL NuGet Package will start to install and after a minute or two, it will be ready to use.
The IronXL library may be installed directly using the NuGet Package Manager UI. To install IronXL, go through the following steps:
Access the NuGet Package Manager by going to Tools > NuGet Package Manager > Manage packages for Solution...
From the NuGet Package Manager submenu, click on Manage NuGet Packages for Solution to access the NuGet Package Manager
IronXL.Excel
package. It will automatically install the library.IronXL offers the ability to read Excel sheets programmatically without any software. Just create a C# .NET project and with just only few lines of code, you can read Excel files in your console.
Reading XLSX files in C# is quite easy using IronXL. The below example will discuss how reading a Microsoft Excel workbook using C# is a piece of cake.
This is an example of an XLSX file containing data from the range A1 to D5 for the following example.
The Excel File that will be used in this example
using IronXL;
using System;
using System.Linq;
// Load the workbook from a file
WorkBook workBook = WorkBook.Load("test.xlsx");
// Access the first worksheet in the workbook
WorkSheet workSheet = workBook.WorkSheets[0];
// Print the content of the worksheet to the console
Console.Write(workSheet);
using IronXL;
using System;
using System.Linq;
// Load the workbook from a file
WorkBook workBook = WorkBook.Load("test.xlsx");
// Access the first worksheet in the workbook
WorkSheet workSheet = workBook.WorkSheets[0];
// Print the content of the worksheet to the console
Console.Write(workSheet);
Imports IronXL
Imports System
Imports System.Linq
' Load the workbook from a file
Private workBook As WorkBook = WorkBook.Load("test.xlsx")
' Access the first worksheet in the workbook
Private workSheet As WorkSheet = workBook.WorkSheets(0)
' Print the content of the worksheet to the console
Console.Write(workSheet)
The output created from the above code example
Using IronXL, you can read multiple Excel workbooks at the same time. In the source code below, multiple Excel files are read.
using IronXL;
using System;
using System.Linq;
// Load the first workbook and access its first worksheet
WorkBook workBook = WorkBook.Load("test.xlsx");
WorkSheet workSheet = workBook.WorkSheets[0];
Console.WriteLine(workSheet);
Console.WriteLine();
// Load the second workbook (CSV format) and access its first worksheet
WorkBook workBook2 = WorkBook.Load("Example2.Sheet0.csv");
WorkSheet workSheet2 = workBook2.WorkSheets[0];
Console.WriteLine(workSheet2);
Console.WriteLine();
using IronXL;
using System;
using System.Linq;
// Load the first workbook and access its first worksheet
WorkBook workBook = WorkBook.Load("test.xlsx");
WorkSheet workSheet = workBook.WorkSheets[0];
Console.WriteLine(workSheet);
Console.WriteLine();
// Load the second workbook (CSV format) and access its first worksheet
WorkBook workBook2 = WorkBook.Load("Example2.Sheet0.csv");
WorkSheet workSheet2 = workBook2.WorkSheets[0];
Console.WriteLine(workSheet2);
Console.WriteLine();
Imports IronXL
Imports System
Imports System.Linq
' Load the first workbook and access its first worksheet
Private workBook As WorkBook = WorkBook.Load("test.xlsx")
Private workSheet As WorkSheet = workBook.WorkSheets(0)
Console.WriteLine(workSheet)
Console.WriteLine()
' Load the second workbook (CSV format) and access its first worksheet
Dim workBook2 As WorkBook = WorkBook.Load("Example2.Sheet0.csv")
Dim workSheet2 As WorkSheet = workBook2.WorkSheets(0)
Console.WriteLine(workSheet2)
Console.WriteLine()
Outputting the contents of more than one Excel document
IronXL offers another breakthrough feature to read multiple sheets in a single C# .NET program. You can use this feature for side-by-side comparisons. The below example will read multiple Excel sheets.
using IronXL;
using System;
// Load the workbook that contains multiple sheets
WorkBook workBook = WorkBook.Load("multiple.xlsx");
// Access the first worksheet
WorkSheet workSheet = workBook.WorkSheets[0];
Console.WriteLine(workSheet);
Console.WriteLine();
// Access the second worksheet
WorkSheet workSheet1 = workBook.WorkSheets[1];
Console.WriteLine(workSheet1);
Console.WriteLine();
using IronXL;
using System;
// Load the workbook that contains multiple sheets
WorkBook workBook = WorkBook.Load("multiple.xlsx");
// Access the first worksheet
WorkSheet workSheet = workBook.WorkSheets[0];
Console.WriteLine(workSheet);
Console.WriteLine();
// Access the second worksheet
WorkSheet workSheet1 = workBook.WorkSheets[1];
Console.WriteLine(workSheet1);
Console.WriteLine();
Imports IronXL
Imports System
' Load the workbook that contains multiple sheets
Private workBook As WorkBook = WorkBook.Load("multiple.xlsx")
' Access the first worksheet
Private workSheet As WorkSheet = workBook.WorkSheets(0)
Console.WriteLine(workSheet)
Console.WriteLine()
' Access the second worksheet
Dim workSheet1 As WorkSheet = workBook.WorkSheets(1)
Console.WriteLine(workSheet1)
Console.WriteLine()
Outputting the contents of more than one worksheet in a single Excel File
Reading Excel files in C# can be a difficult task for those new to programming. However, by using a library such as IronXL, the process becomes much simpler and more manageable.
IronXL is a powerful C# Excel library that provides a wide range of features for working with multiple Excel files or multiple worksheets at the same time.
For more information on how to read Excel files using IronXL, please visit the Read Excel Spreadsheets Code Example.
IronXL is free for development purposes but requires a license for commercial use. View the Reading Excel File in C# Tutorial for more code examples and step-by-step instructions on how to create and read Excel files.
IronXL is a C# library that allows developers to easily read, write, and manipulate Excel files without the need for Microsoft Excel to be installed on the machine. It provides a simple and easy-to-use API for working with Excel data.
IronXL offers features such as reading and writing Excel files in various formats (XLS, XLSX, CSV, XML), support for password-protected files, chart creation, working with formulas, cell styling, and saving/exporting in different formats.
To create a C# project for using IronXL, start Visual Studio, create a new C# Console Application, and ensure you select the latest .NET Framework version. You can add IronXL to your project by installing it via NuGet.
IronXL can be installed via the NuGet Package Manager Console using the command 'Install-Package IronXL.Excel' or through the NuGet Package Manager UI in Visual Studio.
Yes, IronXL allows you to read multiple Excel files at the same time. You can load and process each file separately using the WorkBook and WorkSheet classes.
Yes, IronXL can read multiple worksheets from a single Excel file, enabling side-by-side comparisons and more complex data manipulations.
IronXL is free for development purposes, but it requires a license for commercial use.
To read an XLSX file, load the workbook using WorkBook.Load('file.xlsx'), access the desired worksheet, and then process its content using the WorkSheet class.