Skip to footer content
USING IRONXL

How to Work with Excel Files in C#: Figure 1 - Tutorial

IronXL is a powerful C# library that enables developers to read, write, and manipulate Excel files without requiring Microsoft Excel installation, offering cross-platform compatibility and supporting formats like XLS, XLSX, CSV with an intuitive API.

How Do I Work with Excel Workbook in C#?

  1. Create a Visual Studio project and add the IronXL NuGet package.
  2. Create an Excel file without Interop.
  3. Add Style to Excel file using IronXL.
  4. Read values from Excel and calculate.
  5. Convert Excel to HTML for web usage.

What Is IronXL Library?

IronXL is a robust library for .NET that simplifies working with Excel files. It features an intuitive API that simplifies Excel document manipulation, supporting various formats like XLS, XLSX, and CSV. This versatility allows easy manipulation of cell values, formulas, and formatting. IronXL is optimized for performance, capable of efficiently handling large files and complex data operations while ensuring efficient memory usage. Its cross-platform compatibility enhances its utility across different operating systems. Here are its key features and benefits:

What Are the Key Features of IronXL?

  1. Import and Export:

  2. Data Manipulation:

  3. Styling and Formatting:

  4. Security:

  5. Cross Platform Compatibility:

Why Should I Choose IronXL Over Other Excel Libraries?

  1. No Need for Microsoft Office: IronXL does not require Microsoft Office to be installed, making it lightweight and easy to deploy.
  2. Ease of Use: The API is intuitive and easy to use, allowing developers to quickly integrate Excel functionality into their applications.
  3. Performance: IronXL is optimized for performance, ensuring fast and efficient processing of large Excel files.
  4. Versatility: Suitable for a wide range of applications, including web, desktop, and cloud-based solutions.
  5. Comprehensive Documentation: Extensive documentation and examples are available, making it easier for developers to get started and find solutions to common problems.

How Do I Get Started with IronXL?

To use IronXL in your .NET projects, you need to ensure that your development environment meets the following prerequisites:

What Are the Prerequisites for Using IronXL?

  1. .NET Framework: IronXL supports .NET Framework 4.5 and above.
  2. .NET Core and .NET Standard: Compatible with .NET Core 2, 3, 5, 6, 7, 8 and 9.
  3. Operating Systems: Works on Windows, macOS, and Linux. Compatible with Docker, Azure, and AWS.
  4. No Need for Microsoft Office: IronXL doesn't require Office or Excel Interop.
  5. Code editor: Any C# code editor like Visual Studio.

How Do I Install IronXL in My Project?

You can install IronXL via NuGet Package Manager in Visual Studio or using the Package Manager Console with the following command:

dotnet add package IronXL.Excel --version 2024.8.5
dotnet add package IronXL.Excel --version 2024.8.5
SHELL

For more detailed installation instructions including setup for Blazor, .NET MAUI, or VB.NET projects, refer to the official documentation.

How Do I Create My First Excel File with IronXL?

Let's develop a Visual Studio project and add the IronXL library to get started with working on an Excel file.

How Do I Create a Visual Studio Project and Add IronXL?

Open Microsoft Visual Studio and select 'Create a new project' to get started.

Visual Studio 2022 start screen showing options to open recent projects, clone a repository, open a project/solution, open a local folder, or create a new project.

Select the project template of your choice. Here we've selected Console application for simplicity.

Visual Studio's 'Create a new project' dialog showing Console App options for C#, with both .NET Core and .NET Framework versions available.

Now enter the project name and location for the project.

Visual Studio project configuration dialog showing settings for a new C# console application named 'WorkingWithIronXL' targeting multiple platforms including Windows, Linux, and macOS.

Select the .NET Framework version you prefer. We've selected the latest available on our machine.

Visual Studio project creation dialog showing Console App configuration with .NET 8.0 framework selected and additional options for top-level statements and AOT publishing

Once you click the Create button, the project will be created and ready for use. Open Solution Explorer to check the project files.

Visual Studio NuGet Package Manager showing IronXL.Excel package installation with version 2024.8.5 selected for a C# project named WorkingWithIronXL

Now, let's install the IronXL library from the NuGet package manager as shown above.

How Do I Create an Excel File Without Interop?

Now let's create an Excel file without using Microsoft Interop library. IronXL provides a simple and intuitive way to create spreadsheets programmatically.

using IronXL;

namespace WorkingWithIronXL
{
    public class Program
    {
        public static void Main()
        {
            // Create new Excel WorkBook Object
            WorkBook workBook = WorkBook.Create();
            // Create WorkSheet
            WorkSheet workSheet = workBook.CreateWorkSheet("newXlDemo");
            // Add data in new worksheet
            workSheet["A1"].Value = "IronXL is the best Excel library";           
            // Save the Excel file as XLSX
            workBook.SaveAs("myIronXlDemo.xlsx");
        }
    }
}
using IronXL;

namespace WorkingWithIronXL
{
    public class Program
    {
        public static void Main()
        {
            // Create new Excel WorkBook Object
            WorkBook workBook = WorkBook.Create();
            // Create WorkSheet
            WorkSheet workSheet = workBook.CreateWorkSheet("newXlDemo");
            // Add data in new worksheet
            workSheet["A1"].Value = "IronXL is the best Excel library";           
            // Save the Excel file as XLSX
            workBook.SaveAs("myIronXlDemo.xlsx");
        }
    }
}
$vbLabelText   $csharpLabel

Code Explanation

  1. We add the IronXL namespace to start working with the library.
  2. Create an Excel object with WorkBook.Create() to create an XLSX file.
  3. Call CreateWorkSheet method to create a worksheet inside the workbook.
  4. Add values to cells using workSheet["A1"].Value.
  5. Save the Excel file using workBook.SaveAs by providing a filename.

Output Excel file

Excel spreadsheet showing 'IronXL is the best Excel library' text in cell A1, demonstrating programmatic Excel file creation using IronXL in C#.

Why Does IronXL Not Require Interop?

Unlike traditional approaches that rely on Microsoft Excel Interop, IronXL is a standalone .NET library that reads and writes Excel files directly. This means:

  • No Microsoft Office installation required
  • Better performance and memory usage
  • Cross-platform compatibility (Linux, macOS, Docker)
  • No COM object cleanup issues
  • Thread-safe operations

What File Formats Can I Save To?

IronXL supports saving to multiple formats:

// Save as different Excel formats
workBook.SaveAs("file.xlsx"); // Excel 2007+ format
workBook.SaveAs("file.xls");  // Excel 97-2003 format
workBook.SaveAs("file.xlsm"); // Excel with macros

// Export to other formats
workBook.SaveAsCsv("file.csv", ",");  // CSV with comma delimiter
workBook.SaveAsJson("file.json");     // JSON format
workBook.SaveAsXml("file.xml");       // XML format
// Save as different Excel formats
workBook.SaveAs("file.xlsx"); // Excel 2007+ format
workBook.SaveAs("file.xls");  // Excel 97-2003 format
workBook.SaveAs("file.xlsm"); // Excel with macros

// Export to other formats
workBook.SaveAsCsv("file.csv", ",");  // CSV with comma delimiter
workBook.SaveAsJson("file.json");     // JSON format
workBook.SaveAsXml("file.xml");       // XML format
$vbLabelText   $csharpLabel

How Do I Handle Errors During File Creation?

IronXL provides comprehensive error handling. Here's a best practice example:

try 
{
    WorkBook workBook = WorkBook.Create();
    WorkSheet workSheet = workBook.CreateWorkSheet("Demo");
    workSheet["A1"].Value = "Sample Data";

    // Check if directory exists
    string directory = @"C:\ExcelFiles\";
    if (!Directory.Exists(directory))
    {
        Directory.CreateDirectory(directory);
    }

    workBook.SaveAs(Path.Combine(directory, "output.xlsx"));
}
catch (Exception ex)
{
    Console.WriteLine($"Error creating Excel file: {ex.Message}");
}
try 
{
    WorkBook workBook = WorkBook.Create();
    WorkSheet workSheet = workBook.CreateWorkSheet("Demo");
    workSheet["A1"].Value = "Sample Data";

    // Check if directory exists
    string directory = @"C:\ExcelFiles\";
    if (!Directory.Exists(directory))
    {
        Directory.CreateDirectory(directory);
    }

    workBook.SaveAs(Path.Combine(directory, "output.xlsx"));
}
catch (Exception ex)
{
    Console.WriteLine($"Error creating Excel file: {ex.Message}");
}
$vbLabelText   $csharpLabel

How Do I Add Styling to Excel Files Using IronXL?

Now let's see how to add styles to Excel cells. IronXL provides comprehensive styling options for creating professional-looking spreadsheets.

using IronXL;

namespace WorkingWithIronXL
{
    public class Program
    {
        public static void Main()
        {
            // Create a new workbook
            WorkBook workBook = WorkBook.Create(ExcelFileFormat.XLSX);
            // Create a new worksheet
            WorkSheet workSheet = workBook.CreateWorkSheet("StyledSheet");
            // Add multiple values to cells
            workSheet["A1"].Value = "This Styled Text with Awesome IronXL library";
            workSheet["A2"].Value = 999999;
            // Apply styles to cells
            workSheet["A1"].Style.Font.Bold = true;
            workSheet["A1"].Style.Font.Italic = true;
            workSheet["A1"].Style.Font.Height = 14;
            workSheet["A1"].Style.Font.Color = "#FF0000"; // Red color
            workSheet["A2"].Style.BottomBorder.Type = IronXL.Styles.BorderType.Double;
            workSheet["A2"].Style.BottomBorder.SetColor("#00FF00"); // Green color
            // Save the workbook
            workBook.SaveAs("myIronXlWriteDemo.xlsx");
        }
    }
}
using IronXL;

namespace WorkingWithIronXL
{
    public class Program
    {
        public static void Main()
        {
            // Create a new workbook
            WorkBook workBook = WorkBook.Create(ExcelFileFormat.XLSX);
            // Create a new worksheet
            WorkSheet workSheet = workBook.CreateWorkSheet("StyledSheet");
            // Add multiple values to cells
            workSheet["A1"].Value = "This Styled Text with Awesome IronXL library";
            workSheet["A2"].Value = 999999;
            // Apply styles to cells
            workSheet["A1"].Style.Font.Bold = true;
            workSheet["A1"].Style.Font.Italic = true;
            workSheet["A1"].Style.Font.Height = 14;
            workSheet["A1"].Style.Font.Color = "#FF0000"; // Red color
            workSheet["A2"].Style.BottomBorder.Type = IronXL.Styles.BorderType.Double;
            workSheet["A2"].Style.BottomBorder.SetColor("#00FF00"); // Green color
            // Save the workbook
            workBook.SaveAs("myIronXlWriteDemo.xlsx");
        }
    }
}
$vbLabelText   $csharpLabel

Code Explanation

  1. Create an Excel file using WorkBook.Create.
  2. Create a worksheet using workBook.CreateWorkSheet.
  3. Add values to cells using workSheet["A1"].Value.
  4. Add styles to cells using properties like workSheet["A1"].Style.Font.Bold.
  5. Save the workbook using workBook.SaveAs.

Output Excel File

Excel spreadsheet showing red italic text 'This Styled Text with Awesome IronXL library' in cell A1, with '999999' in green text in cell A2.

What Styling Options Are Available?

IronXL offers extensive styling options including:

How Do I Apply Styles to Multiple Cells?

You can apply styles to ranges of cells efficiently:

// Apply styles to a range
var range = workSheet["A1:D10"];
foreach (var cell in range)
{
    cell.Style.Font.Bold = true;
    cell.Style.Font.Color = "#0000FF"; // Blue
    cell.Style.SetBackgroundColor("#FFFF00"); // Yellow background
}
// Apply styles to a range
var range = workSheet["A1:D10"];
foreach (var cell in range)
{
    cell.Style.Font.Bold = true;
    cell.Style.Font.Color = "#0000FF"; // Blue
    cell.Style.SetBackgroundColor("#FFFF00"); // Yellow background
}
$vbLabelText   $csharpLabel

Can I Use Conditional Formatting?

Yes, IronXL supports conditional formatting:

// Add conditional formatting rule
var rule = workSheet.ConditionalFormatting.CreateConditionalFormattingRule(
    ComparisonOperator.GreaterThan, "100");
rule.FontFormatting.Bold = true;
rule.FontFormatting.FontColor = "#FF0000"; // Red for values > 100
workSheet.ConditionalFormatting.AddConditionalFormatting("A1:A10", rule);
// Add conditional formatting rule
var rule = workSheet.ConditionalFormatting.CreateConditionalFormattingRule(
    ComparisonOperator.GreaterThan, "100");
rule.FontFormatting.Bold = true;
rule.FontFormatting.FontColor = "#FF0000"; // Red for values > 100
workSheet.ConditionalFormatting.AddConditionalFormatting("A1:A10", rule);
$vbLabelText   $csharpLabel

How Do I Read Values from Excel and Calculate?

Now let's see how to read Excel files using IronXL and perform calculations. IronXL supports various mathematical functions for data analysis.

using IronXL;
using System;

namespace WorkingWithIronXL
{
    internal class IronXlDemo
    {
        public static void ReadData()
        {
            // Load the Excel worksheet
            WorkBook workBook = WorkBook.Load("sampleEmployeeData.xlsx");
            // Select the first worksheet
            WorkSheet workSheet = workBook.WorkSheets[0];
            // Read a specific cell value
            int cellValue = workSheet["A2"].IntValue;
            Console.WriteLine($"Value in A2: {cellValue}");
            // Read a range of cells
            foreach (var cell in workSheet["A1:H10"])
            {
                Console.Write($"{cell.Text}\t");
                if(cell.AddressString.Contains("H"))
                {
                    Console.WriteLine();
                }
            }
            // Calculate aggregate values
            decimal sum = workSheet["F2:F10"].Sum();
            Console.WriteLine($"Sum of F2:F10: {sum}");
        }
    }
}
using IronXL;
using System;

namespace WorkingWithIronXL
{
    internal class IronXlDemo
    {
        public static void ReadData()
        {
            // Load the Excel worksheet
            WorkBook workBook = WorkBook.Load("sampleEmployeeData.xlsx");
            // Select the first worksheet
            WorkSheet workSheet = workBook.WorkSheets[0];
            // Read a specific cell value
            int cellValue = workSheet["A2"].IntValue;
            Console.WriteLine($"Value in A2: {cellValue}");
            // Read a range of cells
            foreach (var cell in workSheet["A1:H10"])
            {
                Console.Write($"{cell.Text}\t");
                if(cell.AddressString.Contains("H"))
                {
                    Console.WriteLine();
                }
            }
            // Calculate aggregate values
            decimal sum = workSheet["F2:F10"].Sum();
            Console.WriteLine($"Sum of F2:F10: {sum}");
        }
    }
}
$vbLabelText   $csharpLabel

Code Explanation

  1. Load an Excel file using WorkBook.Load.
  2. Access the first worksheet in the workbook.
  3. Read a specific cell's value and display it using Console.WriteLine.
  4. Iterate through a range of cells and print each value. Print new lines after column H.
  5. Calculate the sum of values in range F2:F10 and print it.

Input Excel

Excel spreadsheet showing employee data with columns for ID, First Name, Last Name, Gender, Country, Age, Date, and a unique identifier, displaying 9 rows of sample employee records.

Output

Console output showing a data table with 10 rows of person records including names, gender, country, age, date, and ID fields, followed by a sum calculation of column F2:F10 equaling 323.

What Data Types Can I Read from Cells?

IronXL supports reading various data types from cells:

// Different ways to read cell values
string textValue = workSheet["A1"].StringValue;
int intValue = workSheet["B1"].IntValue;
decimal decimalValue = workSheet["C1"].DecimalValue;
double doubleValue = workSheet["D1"].DoubleValue;
DateTime dateValue = workSheet["E1"].DateTimeValue;
bool boolValue = workSheet["F1"].BoolValue;

// Read formula results
string formulaResult = workSheet["G1"].FormattedCellValue;
// Different ways to read cell values
string textValue = workSheet["A1"].StringValue;
int intValue = workSheet["B1"].IntValue;
decimal decimalValue = workSheet["C1"].DecimalValue;
double doubleValue = workSheet["D1"].DoubleValue;
DateTime dateValue = workSheet["E1"].DateTimeValue;
bool boolValue = workSheet["F1"].BoolValue;

// Read formula results
string formulaResult = workSheet["G1"].FormattedCellValue;
$vbLabelText   $csharpLabel

How Do I Handle Empty or Null Cells?

IronXL provides safe ways to handle empty cells:

// Check if cell is empty
if (workSheet["A1"].IsEmpty)
{
    Console.WriteLine("Cell A1 is empty");
}

// Use null-coalescing for safe value reading
string value = workSheet["A1"].StringValue ?? "Default Value";

// Check for specific content types
if (workSheet["B1"].IsNumeric)
{
    decimal numValue = workSheet["B1"].DecimalValue;
}
// Check if cell is empty
if (workSheet["A1"].IsEmpty)
{
    Console.WriteLine("Cell A1 is empty");
}

// Use null-coalescing for safe value reading
string value = workSheet["A1"].StringValue ?? "Default Value";

// Check for specific content types
if (workSheet["B1"].IsNumeric)
{
    decimal numValue = workSheet["B1"].DecimalValue;
}
$vbLabelText   $csharpLabel

What Aggregate Functions Are Available?

IronXL supports various aggregate functions:

// Available aggregate functions
decimal sum = workSheet["A1:A10"].Sum();
decimal avg = workSheet["A1:A10"].Avg();
decimal min = workSheet["A1:A10"].Min();
decimal max = workSheet["A1:A10"].Max();
int count = workSheet["A1:A10"].Count();
// Available aggregate functions
decimal sum = workSheet["A1:A10"].Sum();
decimal avg = workSheet["A1:A10"].Avg();
decimal min = workSheet["A1:A10"].Min();
decimal max = workSheet["A1:A10"].Max();
int count = workSheet["A1:A10"].Count();
$vbLabelText   $csharpLabel

How Do I Convert Excel to HTML for Web Usage?

Let's see how to convert Excel to HTML for web usage. This is particularly useful for displaying Excel data in web applications.

using IronXL;
using IronXL.Options;

namespace WorkingWithIronXL
{
    internal class IronXlDemo
    {
        public static void ConvertToHtml()
        {
            WorkBook workBook = WorkBook.Load("sampleEmployeeData.xlsx");
            var options = new HtmlExportOptions()
            {
                // Set row/column numbers visible in HTML document
                OutputRowNumbers = true,
                OutputColumnHeaders = true,
                // Set hidden rows/columns visible in HTML document
                OutputHiddenRows = true,
                OutputHiddenColumns = true,
                // Set leading spaces as non-breaking
                OutputLeadingSpacesAsNonBreaking = true
            };
            // Export workbook to the HTML file
            workBook.ExportToHtml("workBook.html", options);
        }
    }
}
using IronXL;
using IronXL.Options;

namespace WorkingWithIronXL
{
    internal class IronXlDemo
    {
        public static void ConvertToHtml()
        {
            WorkBook workBook = WorkBook.Load("sampleEmployeeData.xlsx");
            var options = new HtmlExportOptions()
            {
                // Set row/column numbers visible in HTML document
                OutputRowNumbers = true,
                OutputColumnHeaders = true,
                // Set hidden rows/columns visible in HTML document
                OutputHiddenRows = true,
                OutputHiddenColumns = true,
                // Set leading spaces as non-breaking
                OutputLeadingSpacesAsNonBreaking = true
            };
            // Export workbook to the HTML file
            workBook.ExportToHtml("workBook.html", options);
        }
    }
}
$vbLabelText   $csharpLabel

Code Explanation

  1. Load the Excel file using the Load method.
  2. Set options for HTML conversion using HtmlExportOptions.
  3. Use ExportToHtml method to convert and save as HTML.

Input

Excel spreadsheet showing sample employee data with columns for ID, First Name, Last Name, Gender, Country, Age, Date, and Id, containing 9 rows of employee information.

Output

HTML table displaying Excel data with columns for First Name, Last Name, Gender, Country, Age, Date, and Id, showing 9 rows of sample employee data.

What HTML Export Options Are Available?

IronXL provides various HTML export options:

var htmlOptions = new HtmlExportOptions()
{
    // Table formatting options
    OutputRowNumbers = true,
    OutputColumnHeaders = true,

    // Visibility options  
    OutputHiddenRows = false,
    OutputHiddenColumns = false,

    // Formatting preservation
    OutputLeadingSpacesAsNonBreaking = true,

    // Custom CSS class
    TableCssClass = "excel-table"
};
var htmlOptions = new HtmlExportOptions()
{
    // Table formatting options
    OutputRowNumbers = true,
    OutputColumnHeaders = true,

    // Visibility options  
    OutputHiddenRows = false,
    OutputHiddenColumns = false,

    // Formatting preservation
    OutputLeadingSpacesAsNonBreaking = true,

    // Custom CSS class
    TableCssClass = "excel-table"
};
$vbLabelText   $csharpLabel

How Do I Preserve Formatting in HTML?

IronXL automatically preserves basic formatting when exporting to HTML. For advanced formatting preservation:

// Export with inline CSS styles
workBook.ExportToHtml("styled.html", new HtmlExportOptions
{
    OutputRowNumbers = false,
    OutputColumnHeaders = true,
    // Preserves cell styles as inline CSS
    PreserveStyles = true
});
// Export with inline CSS styles
workBook.ExportToHtml("styled.html", new HtmlExportOptions
{
    OutputRowNumbers = false,
    OutputColumnHeaders = true,
    // Preserves cell styles as inline CSS
    PreserveStyles = true
});
$vbLabelText   $csharpLabel

Can I Export Specific Worksheets Only?

Yes, you can export individual worksheets:

// Export specific worksheet
WorkSheet sheet = workBook.GetWorkSheet("Sheet1");
sheet.SaveAsHtml("sheet1.html");

// Export multiple specific sheets
foreach (var sheetName in new[] { "Sheet1", "Sheet3" })
{
    workBook.GetWorkSheet(sheetName).SaveAsHtml($"{sheetName}.html");
}
// Export specific worksheet
WorkSheet sheet = workBook.GetWorkSheet("Sheet1");
sheet.SaveAsHtml("sheet1.html");

// Export multiple specific sheets
foreach (var sheetName in new[] { "Sheet1", "Sheet3" })
{
    workBook.GetWorkSheet(sheetName).SaveAsHtml($"{sheetName}.html");
}
$vbLabelText   $csharpLabel

What Are the Real-World Use Cases for IronXL?

IronXL is a versatile .NET library with a wide range of real-world applications, including:

1. Business Reporting:

  • Automating periodic reports like sales summaries and financial statements.
  • Creating custom dashboards from various data sources.
  • Exporting data to Excel for stakeholder presentations.

2. Data Analysis:

3. Inventory Management:

  • Managing product inventories with stock levels and supplier details.
  • Generating inventory reports to track trends.
  • Importing CSV data from suppliers.

4. Customer Relationship Management (CRM):

5. Educational Institutions:

  • Creating student grade books and attendance records.
  • Generating exam results and performance analysis.
  • Using formulas to calculate grades automatically.

6. Financial Services:

  • Automating financial models, budgets, and forecasts.
  • Consolidating financial data for comprehensive reporting.
  • Creating charts for visual analysis.

7. Human Resources:

  • Managing employee data including payroll and evaluations.
  • Generating reports on HR metrics and demographics.
  • Protecting sensitive data with password encryption.

8. Project Management:

  • Tracking project timelines and resource allocation.
  • Creating Gantt charts and project management tools.
  • Using named ranges for formula management.

9. E-commerce:

  • Exporting order details, customer information, and sales data from e-commerce platforms to Excel.
  • Analyzing sales trends, customer behavior, and product performance.

10. Healthcare:

  • Managing patient records and appointment schedules.
  • Analyzing healthcare data to improve patient care.
  • Securing patient data with worksheet protection.

Which Industries Benefit Most from IronXL?

Industries that deal with large amounts of structured data benefit most:

How Does IronXL Handle Large-Scale Data Processing?

IronXL is optimized for performance with:

What Are Common Integration Scenarios?

Common integration scenarios include:

How Do I License IronXL for Production Use?

IronXL is an enterprise library from Iron Software. It requires a license to run. You can download a trial license using your email ID from here. Once submitted, the license is delivered to your email. Place this license at the beginning of your code, before using IronXL:

License.LicenseKey = "your Key Here";
License.LicenseKey = "your Key Here";
$vbLabelText   $csharpLabel

What License Types Are Available?

IronXL offers several license types:

  • Lite License: For individual developers
  • Professional License: For small teams
  • Enterprise License: For large organizations
  • SaaS License: For cloud-based applications
  • OEM License: For redistribution

How Do I Apply the License Key?

You can apply the license key in multiple ways:

// Method 1: In code
IronXL.License.LicenseKey = "YOUR-LICENSE-KEY";

// Method 2: Using app.config or web.config
// Add to configuration file:
// <appSettings>
//   <add key="IronXL.LicenseKey" value="YOUR-LICENSE-KEY"/>
// </appSettings>

// Method 3: Using environment variable
Environment.SetEnvironmentVariable("IRONXL_LICENSE_KEY", "YOUR-LICENSE-KEY");
// Method 1: In code
IronXL.License.LicenseKey = "YOUR-LICENSE-KEY";

// Method 2: Using app.config or web.config
// Add to configuration file:
// <appSettings>
//   <add key="IronXL.LicenseKey" value="YOUR-LICENSE-KEY"/>
// </appSettings>

// Method 3: Using environment variable
Environment.SetEnvironmentVariable("IRONXL_LICENSE_KEY", "YOUR-LICENSE-KEY");
$vbLabelText   $csharpLabel

For web applications, you can also set the license in Web.config.

What Happens When the Trial Expires?

When the trial expires:

  • A watermark appears on generated files
  • Some features may be limited
  • Production deployment is not allowed

To continue using IronXL, purchase a commercial license. The team offers license extensions and upgrades for existing customers.

What Have We Learned About Working with Excel Files in C#?

IronXL is a powerful .NET library for creating, reading, and editing Excel files, offering an intuitive API that simplifies working with Excel documents. It supports multiple formats including XLS, XLSX, and CSV, making it versatile for various use cases. IronXL allows easy manipulation of cell values, formulas, and formatting, and is optimized for performance, efficiently handling large files and complex operations. Its memory management ensures responsive applications, and its cross-platform compatibility makes it valuable for developers on different operating systems.

Whether you're building web applications, desktop software, or cloud services, IronXL provides the tools needed to work effectively with Excel files in C#. For more advanced features, check out the complete documentation and explore the extensive code examples.

Key takeaways:

Stay updated with the latest features and improvements by checking the changelog and milestones for IronXL's continuous enhancements.

Frequently Asked Questions

How can I manipulate Excel files in C# without Microsoft Excel installed?

You can use IronXL, a C# library from Iron Software, to read, write, and manipulate Excel documents without requiring Microsoft Excel. It supports various formats like XLS, XLSX, and CSV, and can be used in applications like web services, desktop, and console.

What steps are involved in setting up a Visual Studio project to work with Excel in C#?

To set up a Visual Studio project for working with Excel in C#, install IronXL via the NuGet Package Manager. Use the command: dotnet add package IronXL.Excel --version 2024.8.5 in the Package Manager Console to add the library to your project.

Can I perform calculations in Excel files using C#?

Yes, using IronXL, you can perform calculations in Excel files. The library supports Excel formulas, allowing you to automate calculations directly within your C# application.

How do I convert an Excel file to HTML using C#?

IronXL provides the ExportToHtml method to convert Excel files to HTML. This method allows customization options to ensure the HTML output meets your requirements.

What are the benefits of using IronXL for Excel file manipulation in C#?

IronXL offers ease of use with an intuitive API, optimized performance for handling large Excel files, and versatility for various applications. Its cross-platform compatibility and comprehensive documentation further enhance its utility.

Can I apply advanced styling to Excel cells using IronXL?

Yes, with IronXL, you can apply advanced styles to Excel cells, such as customizing font, size, color, borders, and alignment using the Style properties on each cell.

Is IronXL suitable for cross-platform Excel file manipulation?

Yes, IronXL is designed to be cross-platform, compatible with Windows, macOS, Linux, and environments like Docker, Azure, and AWS, making it ideal for diverse deployment scenarios.

How do I read cell values from an Excel file using IronXL in C#?

With IronXL, you can read cell values from an Excel file by loading the file using WorkBook.Load, selecting the worksheet, and accessing specific cell values or ranges using their address.

What makes IronXL a powerful tool for handling Excel files in C#?

IronXL is powerful due to its support for multiple formats (XLS, XLSX, CSV), formula and styling capabilities, encryption for security, and its ability to handle large files efficiently across different operating systems.

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