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 demonstrate how to load Excel files using IronXL, a first-class Excel C# library, efficiently and programmatically.
The C# .NET Excel library, IronXL, can be used to read data from and convert Microsoft Excel documents to CSV files. No Microsoft Office, Microsoft.Office.Interop.Excel, or Excel Interop installation is required for IronXL. It is a completely independent .NET Excel applications library. Numerous spreadsheet formats can be read by it. IronXL is not just a static library.
Excel spreadsheets in a .NET context may be easily generated, modified, and viewed thanks to IronXL's straightforward C# API. Core .NET apps, Linux, macOS, Azure, and Xamarin are all fully supported by IronXL. Below is a bulleted list of IronXL's key features that set it apart from other applications for reading Excel files.
With these features, IronXL becomes a flexible and strong library for working with Excel files, giving developers more convenience and flexibility when managing their Excel document-related tasks programmatically. To know more about the IronXL library, refer to those documents.
The IronXL library makes it easy to write data and create and read Excel files, as you will see in the upcoming sections of this newsletter.
The first step, starting a fresh project to make Excel files:
Choose "New Project" from the "File" menu once Visual Studio has launched.
The .NET "Console App" project templates will appear in the dialog box that follows; select them and double-click on "Next."
New Project
You can type any project name you want for the Project after entering the new project's location in the Location area. Press the Next button to continue.
Project Configuration
With the Framework drop-down menu, you can choose a .NET Framework. The long-term supported version of .NET, 6.0, is being used here. Hit "Create" after that.
Target framework Selection
The following solution requires the IronXL library, which you should obtain. To accomplish this, input the below command into the Package Manager Console:
Install-Package IronXL.Excel
IronXL Installation
An alternative to this would be to use the NuGet Package Manager to search for the package "IronXL".
Browsing should result in a list of all NuGet packages linked to IronXL. Then, select the one needed and click the install button.
NuGet Package Manager
The following code allows you to load and read Excel files using IronXL.
using IronXL;
using System.Linq;
// Load the workbook with the name "Demo.xlsx".
WorkBook workBook = WorkBook.Load("Demo.xlsx");
// Access the first worksheet in the workbook.
WorkSheet sheet = workBook.WorkSheets.First();
// Iterate through the range of cells A2 to B10 and print each cell's address and text content.
foreach (var cell in sheet["A2:B10"])
{
Console.WriteLine("Cell {0} has value '{1}'", cell.AddressString, cell.Text);
}
using IronXL;
using System.Linq;
// Load the workbook with the name "Demo.xlsx".
WorkBook workBook = WorkBook.Load("Demo.xlsx");
// Access the first worksheet in the workbook.
WorkSheet sheet = workBook.WorkSheets.First();
// Iterate through the range of cells A2 to B10 and print each cell's address and text content.
foreach (var cell in sheet["A2:B10"])
{
Console.WriteLine("Cell {0} has value '{1}'", cell.AddressString, cell.Text);
}
Imports IronXL
Imports System.Linq
' Load the workbook with the name "Demo.xlsx".
Private workBook As WorkBook = WorkBook.Load("Demo.xlsx")
' Access the first worksheet in the workbook.
Private sheet As WorkSheet = workBook.WorkSheets.First()
' Iterate through the range of cells A2 to B10 and print each cell's address and text content.
For Each cell In sheet("A2:B10")
Console.WriteLine("Cell {0} has value '{1}'", cell.AddressString, cell.Text)
Next cell
The first line of code, using IronXL;
, is called to implement the library into this demo project, which makes the IronXL functionalities available.
Then load the existing Excel file, named "Demo.xlsx", using the method Load
which is available in the WorkBook
object.
In the code, the Load
method can accept three types of inputs: a file name with the path, a stream, and byte arrays. In the above example, the method with the file name and the path is used to load the file.
To perform the read Excel file operation, we obtain the default WorkSheet
by using the First()
method to select the initial worksheet from the workbook's worksheet collection.
Subsequently, the Excel worksheet range is selected using the worksheet object by specifying the cell range. It will then iterate through each of the cell values within the specified range (A2:B10
) and display the value along with the cell address.
Output of Previous Code Example
The above example demonstrates loading an Excel file in C# and its resulting output when using IronXL. It utilizes Excel sheets by referencing the row and column index.
To know more about coding with IronXL, refer to this example.
IronXL is a well-liked Excel add-on that works without the need for any extra external libraries. It has several uses and doesn't need to have Microsoft Excel installed.
All programmable duties involving Microsoft Excel documents can be fully resolved with IronXL. You can add and remove data, search and replace, combine and unmerge data tables or cells, sort strings or numbers, visualize a data table, and save files. Formula computations are also possible with IronXL. You can also set cell data types and examine spreadsheet data with it. The ability to read and write CSV files obtainable with IronXL is a necessity for working with Excel data.
While IronXL offers a free trial, users can choose to upgrade to a paid membership for 1 year to receive updates and customer assistance. IronXL charges extra for security that allows for unfettered distribution. To find out more about the specifics of the pricing, see this licensing page.
IronXL is a C# .NET Excel library used to read data from and convert Microsoft Excel documents to CSV files without the need for Microsoft Office or Excel Interop installations.
To load an Excel file using IronXL, you need to install the IronXL NuGet package and use the WorkBook.Load method to load the Excel file programmatically.
IronXL supports various Excel file formats including XLSX, CSV, XLS, XLST, TSV, and XLSM.
Yes, IronXL works with both .NET Core and .NET Framework applications.
IronXL is compatible with Windows, macOS, and Linux operating systems.
Yes, IronXL is optimized for performance in multi-threaded scenarios, allowing it to manage substantial amounts of data efficiently.
IronXL can handle various data types in Excel columns, including text, integers, dates, currencies, formulas, and percentages.
Yes, IronXL allows you to create, modify, and view Excel files in a .NET context using its straightforward C# API.
IronXL offers ease of use, compatibility with multiple platforms, support for various Excel formats, and does not require Microsoft Excel to be installed on the system.
IronXL offers a free trial, and users can upgrade to a paid membership for additional features, updates, and customer support.