Skip to footer content
USING IRONXL

.NET Excel Library (Developer Tutorial)

IronXL enables you to create, read, and export Excel files in C#/.NET with just a few lines of code, without requiring Microsoft Office installations, making it perfect for fast-moving startups that need quick Excel integration capabilities.

What Makes IronXL the Best Excel Library for .NET Development?

In this article, we'll explore IronXL, an Excel library that simplifies working with Microsoft Excel documents programmatically in .NET. We'll create an Excel spreadsheet environment to read Excel worksheets, write Excel tables, and export spreadsheet files to CSV.

Why Choose IronXL Over Microsoft.Office.Interop?

Documents created in Microsoft Excel can be read and converted to CSV files using the C# IronXL .NET Excel library. IronXL is a standalone .NET software library that doesn't need Microsoft Office, Microsoft.Office.Interop.Excel, or Excel Interop to be installed. It can read several spreadsheet formats and is not just a static library.

IronXL's simple C# API makes it easy to read multiple worksheets, modify, and generate Excel spreadsheets in a .NET environment. It fully supports Xamarin, Linux, macOS, Azure, .NET Core applications, and .NET Framework.

For startup founders who need rapid deployment, IronXL eliminates the dependency on Microsoft Office installations across development and production servers, significantly reducing infrastructure complexity and licensing costs. The library's cross-platform support ensures your Excel processing capabilities work seamlessly whether you're deploying to Linux containers, Azure Functions, or traditional Windows servers.

Which Platforms and Formats Does IronXL Support?

The extensive format support means you can convert between different spreadsheet file types effortlessly, whether you're importing Excel data from client uploads or exporting to different formats for various stakeholders.

How Do I Set Up a .NET Project to Use IronXL?

The next sections show you how simple it is to create and read Excel files with the IronXL library.

What Are the Steps to Create a New Console Project?

Step 1: Launch a new project to create Excel files.

After starting Visual Studio, select "New Project" from the "File" menu.

In the resulting dialogue box, select the "Console App" .NET Project templates, then click "Next."

Visual Studio 'Add a new project' dialog showing various .NET project templates including Console App, ASP.NET Core Web App, Blazor Server App, and ASP.NET Core Web API, with Console App highlighted for Excel library tutorial New Project

Once you've entered the new project's location in the Location field, you can enter any project name you choose. Click the Next button to proceed.

Visual Studio new project configuration screen showing Console App template selection with C#, cross-platform OS options (Linux, macOS, Windows), and fields for entering project name and location for Excel library development Project Configuration

Which .NET Framework Version Should I Choose?

Select a .NET Framework using the Framework drop-down option. Here, we're using .NET 6.0, the long-term supported version. Then press Create.

Visual Studio project configuration window showing Console App settings with .NET 6.0 LTS framework selected and platform options for C#, Linux, macOS, Windows, and Console for Excel library development Framework Selection

For startup environments, choosing .NET 6.0 LTS ensures long-term stability and support, reducing the need for framework upgrades during critical growth phases. This version also provides excellent performance improvements and is fully compatible with Docker deployments and Azure Functions.

How Do I Install IronXL Via NuGet Package Manager?

Get the IronXL library, which is required for the following solution. To do this, enter the following command into the NuGet Package Manager Console:

Install-Package IronXL.Excel

 related to How Do I Install IronXL Via NuGet Package Manager? IronXL Installation

Another option is to use the NuGet Package Manager to search for the package "IronXL". Then, select the desired package to download from the list of all NuGet packages related to IronXL.

NuGet Package Manager window showing IronXL.Excel package with version 2023.4.13 ready for installation, displaying 386K downloads and the Install button highlighted for easy Excel library integration NuGet Package Manager

The installation process is straightforward and can be completed in under a minute. For teams using CI/CD pipelines, IronXL can be easily integrated into automated builds. Check the licensing page for startup-friendly pricing options and how to apply license keys in your deployment pipeline.

How Do I Create Excel Files Using IronXL in C#?

With IronXL, you can create new Excel files with just a few lines of code! IronXL can create files in both XLS (older Excel format) and XLSX (current format) as shown in the code samples below.

What's the Minimal Code to Generate a New Excel Workbook?

using IronXL;

public class IronXLExample
{
    public static void Main(string[] args)
    {
        // Create a new workbook
        WorkBook workbook = WorkBook.Create();

        // Create a new worksheet named "Sheet1"
        WorkSheet worksheet = workbook.CreateWorkSheet("Sheet1");

        // Set the value of cell A1
        worksheet["A1"].Value = "test";

        // Save the workbook to a file
        workbook.SaveAs("sample1.xlsx");
    }
}
using IronXL;

public class IronXLExample
{
    public static void Main(string[] args)
    {
        // Create a new workbook
        WorkBook workbook = WorkBook.Create();

        // Create a new worksheet named "Sheet1"
        WorkSheet worksheet = workbook.CreateWorkSheet("Sheet1");

        // Set the value of cell A1
        worksheet["A1"].Value = "test";

        // Save the workbook to a file
        workbook.SaveAs("sample1.xlsx");
    }
}
$vbLabelText   $csharpLabel

The code above demonstrates using the IronXL package to create a new Excel workbook and worksheet. The WorkBook.Create() method creates a new workbook, and then the CreateWorkSheet("Sheet1") function creates a worksheet tab with the specified name. Changes are saved in a specified location using the SaveAs method.

For more complex scenarios, you can add multiple worksheets, apply cell formatting, set cell data formats, and even create Excel charts programmatically:

// Create a workbook with multiple sheets and formatting
WorkBook workbook = WorkBook.Create();
WorkSheet salesSheet = workbook.CreateWorkSheet("Sales");
WorkSheet revenueSheet = workbook.CreateWorkSheet("Revenue");

// Add headers with formatting
salesSheet["A1"].Value = "Product";
salesSheet["B1"].Value = "Quantity";
salesSheet["C1"].Value = "Revenue";

// Apply bold formatting to headers
salesSheet["A1:C1"].Style.Font.Bold = true;

// Add data with number formatting
salesSheet["A2"].Value = "Widget A";
salesSheet["B2"].Value = 150;
salesSheet["C2"].Value = 4500.00;
salesSheet["C2"].FormatString = "$#,##0.00"; // Currency format

// Auto-size columns for better readability
salesSheet.AutoSizeColumn(0);
salesSheet.AutoSizeColumn(1);
salesSheet.AutoSizeColumn(2);

workbook.SaveAs("sales_report.xlsx");
// Create a workbook with multiple sheets and formatting
WorkBook workbook = WorkBook.Create();
WorkSheet salesSheet = workbook.CreateWorkSheet("Sales");
WorkSheet revenueSheet = workbook.CreateWorkSheet("Revenue");

// Add headers with formatting
salesSheet["A1"].Value = "Product";
salesSheet["B1"].Value = "Quantity";
salesSheet["C1"].Value = "Revenue";

// Apply bold formatting to headers
salesSheet["A1:C1"].Style.Font.Bold = true;

// Add data with number formatting
salesSheet["A2"].Value = "Widget A";
salesSheet["B2"].Value = 150;
salesSheet["C2"].Value = 4500.00;
salesSheet["C2"].FormatString = "$#,##0.00"; // Currency format

// Auto-size columns for better readability
salesSheet.AutoSizeColumn(0);
salesSheet.AutoSizeColumn(1);
salesSheet.AutoSizeColumn(2);

workbook.SaveAs("sales_report.xlsx");
$vbLabelText   $csharpLabel

Microsoft Excel interface showing a programmatically created workbook with 'test' entered in cell A1, demonstrating basic Excel file creation with IronXL .NET library Excel Output

Where Can I Find More Examples of Creating Excel Files?

To learn more about creating Excel files, check this tutorial to create one in .NET. You can also explore how to work with Excel in C# without Interop and create Excel charts programmatically.

How Do I Read Excel Data and Export to Different Formats?

Exporting data to XLSX or XLS formats requires only a few lines of code. Below is source code that can be used to export data from an Excel file into a simple tabular format:

What Code Do I Need to Load and Modify Existing Excel Files?

using IronXL;

public class ExcelReadExportExample
{
    public static void Main(string[] args)
    {
        // Load an existing Excel file
        var workbook = WorkBook.LoadExcel("Demo file.xlsx");

        // Get a worksheet from the workbook
        WorkSheet workSheet = workbook.GetWorkSheet("Sheet1");

        // Read the value of cell A1
        string addressVal = workSheet["A1"].ToString();
        Console.WriteLine(addressVal);

        // Modify the value of cell A2
        workSheet["A2"].Value = "test";

        // Save the workbook in multiple formats
        workbook.SaveAs("export.xlsx");
        // Or save as XLS
        workbook.SaveAs("export.xls");
        // Or save the specific worksheet as an XLS file
        workbook.WorkSheets[0].SaveAs("export.xls");
    }
}
using IronXL;

public class ExcelReadExportExample
{
    public static void Main(string[] args)
    {
        // Load an existing Excel file
        var workbook = WorkBook.LoadExcel("Demo file.xlsx");

        // Get a worksheet from the workbook
        WorkSheet workSheet = workbook.GetWorkSheet("Sheet1");

        // Read the value of cell A1
        string addressVal = workSheet["A1"].ToString();
        Console.WriteLine(addressVal);

        // Modify the value of cell A2
        workSheet["A2"].Value = "test";

        // Save the workbook in multiple formats
        workbook.SaveAs("export.xlsx");
        // Or save as XLS
        workbook.SaveAs("export.xls");
        // Or save the specific worksheet as an XLS file
        workbook.WorkSheets[0].SaveAs("export.xls");
    }
}
$vbLabelText   $csharpLabel

How Do I Access Worksheets by Name or Index?

In the preceding example, an existing Excel file is loaded using the LoadExcel method, which takes the file name and path as an argument. The file is then imported into the WorkBook object. Worksheets are loaded using the GetWorkSheet function by specifying the sheet name. The value of a cell can be read by specifying its address. The code also demonstrates modifying a worksheet value and saving the workbook in different file formats using the SaveAs method.

IronXL provides flexible ways to select ranges, read CSV files, and work with various data structures. Here's an expanded example showing different ways to access and manipulate Excel data:

// Load workbook from various sources
WorkBook workbook = WorkBook.Load("data.xlsx");

// Access worksheets in multiple ways
WorkSheet sheet1 = workbook.WorkSheets[0]; // By index
WorkSheet sheet2 = workbook.GetWorkSheet("Sheet2"); // By name

// Read data from ranges
var range = sheet1["A1:C10"];
foreach (var cell in range)
{
    Console.WriteLine($"{cell.Address}: {cell.Value}");
}

// Convert to DataTable for easier processing
DataTable dataTable = sheet1.ToDataTable(true);

// Export to various formats
workbook.SaveAs("output.csv"); // CSV format
workbook.SaveAsJson("output.json"); // JSON format
workbook.SaveAsXml("output.xml"); // XML format
// Load workbook from various sources
WorkBook workbook = WorkBook.Load("data.xlsx");

// Access worksheets in multiple ways
WorkSheet sheet1 = workbook.WorkSheets[0]; // By index
WorkSheet sheet2 = workbook.GetWorkSheet("Sheet2"); // By name

// Read data from ranges
var range = sheet1["A1:C10"];
foreach (var cell in range)
{
    Console.WriteLine($"{cell.Address}: {cell.Value}");
}

// Convert to DataTable for easier processing
DataTable dataTable = sheet1.ToDataTable(true);

// Export to various formats
workbook.SaveAs("output.csv"); // CSV format
workbook.SaveAsJson("output.json"); // JSON format
workbook.SaveAsXml("output.xml"); // XML format
$vbLabelText   $csharpLabel

Console window displaying the successful output 'test' from reading Excel cell data using IronXL .NET library example code Console Output

What Export Options Are Available for Excel Files?

A worksheet can also be referenced either by name or index value to export data from an Excel spreadsheet to a separate file. IronXL supports exporting to multiple formats including CSV, JSON, XML, and HTML. You can also export to DataSet and DataTable for seamless integration with your .NET data processing pipeline.

For startup teams needing to integrate with various systems, IronXL's export capabilities enable quick data interchange. You can load Excel from SQL databases, update database records from Excel, or work with Excel data via DataTable for rapid prototyping and MVP development.

What Are the Next Steps with IronXL?

From creating new files to performing precise calculations, IronXL has you covered for all your Excel projects. Today, we explored how IronXL can create, read, and export Excel files, and saw how with just a few lines of code you can have full control over these processes.

What Advanced Features Does IronXL Offer?

For every programmable task involving Microsoft Excel documents, IronXL offers a comprehensive solution. You can perform formula calculations, sort strings or numbers, cut and add data, search and replace, merge and unmerge cells, visualize data, and save files. You can also set cell data types and validate spreadsheet data. The ability to read and write CSV files enables interaction with Excel data.

Additional advanced features include:

What's the Pricing Model for Startup Teams?

IronXL costs $799 upon launch, but customers can opt to pay a one-year membership fee for improvements and product support. IronXL levies an additional security fee that permits unrestricted redistribution. Visit this licensing page to learn more about pricing details.

For startups, IronXL offers developer licenses that let you evaluate the library without restrictions. The licensing model is transparent with no hidden fees, and you can start with a single developer license and upgrade as your team grows. Check out the troubleshooting guides for applying licenses in different deployment scenarios.

Whether you're building a Blazor application, deploying to AWS Lambda, working with .NET MAUI, or creating ASP.NET web applications, IronXL provides the flexibility and performance needed to ship your Excel features quickly without the overhead of Microsoft Office dependencies.

Frequently Asked Questions

How can I create and read Excel files in .NET without Interop?

Using IronXL, you can easily create and read Excel files in .NET without relying on Microsoft Office Interop. You can use the WorkBook.Create() method to create new Excel files and LoadExcel to read existing ones.

What are the benefits of using a standalone .NET Excel library?

A standalone .NET Excel library like IronXL offers the advantage of not requiring Microsoft Office or Interop installations. It allows for seamless reading, writing, and exporting of Excel files across different platforms such as Windows, macOS, and Linux.

How can I convert Excel files to CSV format programmatically?

IronXL provides functionality to convert Excel files to CSV format effortlessly. Use the SaveAs method to export your Excel workbook to a CSV file format.

Which platforms are compatible with IronXL for working with Excel files?

IronXL is compatible with multiple platforms including Xamarin, Linux, macOS, Azure, .NET Core, and .NET Framework, offering flexibility for developers working within different environments.

What types of data can be handled within Excel columns using IronXL?

IronXL supports a wide range of data types including text, integers, dates, currencies, formulas, and percentages for Excel columns, enabling versatile data handling within spreadsheets.

How do I perform calculations in Excel spreadsheets using a .NET library?

With IronXL, you can perform calculations in Excel spreadsheets by utilizing formulas programmatically. This allows you to automate complex calculations and data processing tasks within your Excel files.

Is it possible to work with multiple worksheets in an Excel file using a .NET library?

Yes, IronXL allows you to work with multiple worksheets within an Excel file. You can easily access, modify, and export data across different worksheets using its API.

How can I set up IronXL in a .NET Core project?

To set up IronXL in a .NET Core project, you can install it via the NuGet Package Manager. Use the command Install-Package IronXL.Excel in the Package Manager Console, or add it through the NuGet Package Manager in Visual Studio.

What licensing and pricing options are available for IronXL?

IronXL offers various licensing options that include a one-year membership fee for improvements and support. Additional costs may be incurred for security features and unrestricted redistribution rights.

Jordi Bardia
Software Engineer
Jordi is most proficient in Python, C# and C++, when he isn’t leveraging his skills at Iron Software; he’s game programming. Sharing responsibilities for product testing, product development and research, Jordi adds immense value to continual product improvement. The varied experience keeps him challenged and engaged, and he ...
Read More