Skip to footer content
USING IRONXL

How to Create Excel Files in C#: Interop vs IronXL

Introduction

Creating Excel files programmatically is a fundamental requirement in many C# applications. While Microsoft.Office.Interop.The traditional approach to creating Excel files in C# using Interop has been Excel. However, it comes with limitations, such as requiring Microsoft Excel to be installed and relying on Primary Interop Assemblies. Modern Excel library alternatives like IronXL allow you to create an Excel workbook, work with multiple worksheets, and generate XLSX or CSV files without Microsoft Office. This article compares how different libraries handle Excel file creation, providing sample code and guidance for .NET developers.

Quick Comparison Overview

Feature

Excel Interop

IronXL

EPPlus

ClosedXML

NPOI

GemBox

Aspose

Excel Installation Required

Yes

No

No

No

No

No

No

Server Deployment

Not Recommended

Yes

Yes

Yes

Yes

Yes

Yes

Platform Support

Windows Only

Cross-Platform

Cross-Platform

Cross-Platform

Cross-Platform

Cross-Platform

Cross-Platform

XLS Support

Yes

Yes

No

No

Yes

Yes

Yes

XLSX Support

Yes

Yes

Yes

Yes

Yes

Yes

Yes

Learning Curve

Steep

Easy

Easy

Easy

Moderate

Easy

Moderate

Commercial License

Office License

From $liteLicense

From €449

Free (MIT)

Free (Apache)

From €590

From $999

Memory Efficiency

Poor

Excellent

Good

Good

Poor

Excellent

Good

Note: “Excel Interop” requires Microsoft Excel to be installed, along with the Primary Interop Assembly. Alternative libraries, such as IronXL, allow you to create Excel files, workbooks, and worksheets without requiring Office, and support xlsx files, CSV files, and multiple worksheets.

Why Move Beyond Excel Interop?

Microsoft.Office.Interop.Excel alternatives are essential because Excel Interop requires Microsoft Excel installed on every machine where your application runs. This dependency creates deployment challenges, especially for server environments where Microsoft explicitly warns against Office automation. Using Interop without Excel results in exceptions, warning messages, or failed attempts to create an Excel document programmatically. Applications also suffer from COM dependency issues, version conflicts, and poor performance due to Excel running as a background process.

Modern Excel libraries, such as IronXL, eliminate these issues. You can create Excel files, write data to worksheets, generate CSV or XML files, and work with new Excel workbooks without relying on Office, the Excel application object, or the Primary Interop Assembly. Developers can also use Visual Studio, Visual Basic, or console application projects to implement Excel automation across Windows or cross-platform environments.

Get started with IronXL's free trial to eliminate these dependencies entirely.

Creating Excel Files with Interop

Let's first look at the traditional approach using Excel Interop:

using Excel = Microsoft.Office.Interop.Excel;
// Create Excel application instance
Excel.Application excelApp = new Excel.Application();
Excel.Workbook workbook = excelApp.Workbooks.Add();
Excel.Worksheet worksheet = (Excel.Worksheet)workbook.Sheets[1];
// Add data to cells
worksheet.Cells[1, 1] = "Product";
worksheet.Cells[1, 2] = "Price";
worksheet.Cells[2, 1] = "Widget";
worksheet.Cells[2, 2] = 9.99;
// Save and cleanup
workbook.SaveAs(@"C:\temp\products.xlsx");
workbook.Close();
excelApp.Quit();
// Release COM objects
System.Runtime.InteropServices.Marshal.ReleaseComObject(worksheet);
System.Runtime.InteropServices.Marshal.ReleaseComObject(workbook);
System.Runtime.InteropServices.Marshal.ReleaseComObject(excelApp);
using Excel = Microsoft.Office.Interop.Excel;
// Create Excel application instance
Excel.Application excelApp = new Excel.Application();
Excel.Workbook workbook = excelApp.Workbooks.Add();
Excel.Worksheet worksheet = (Excel.Worksheet)workbook.Sheets[1];
// Add data to cells
worksheet.Cells[1, 1] = "Product";
worksheet.Cells[1, 2] = "Price";
worksheet.Cells[2, 1] = "Widget";
worksheet.Cells[2, 2] = 9.99;
// Save and cleanup
workbook.SaveAs(@"C:\temp\products.xlsx");
workbook.Close();
excelApp.Quit();
// Release COM objects
System.Runtime.InteropServices.Marshal.ReleaseComObject(worksheet);
System.Runtime.InteropServices.Marshal.ReleaseComObject(workbook);
System.Runtime.InteropServices.Marshal.ReleaseComObject(excelApp);
IRON VB CONVERTER ERROR developers@ironsoftware.com
$vbLabelText   $csharpLabel

This code requires Excel installation, manual COM object cleanup, and won't work on non-Windows platforms. The complexity increases when handling multiple worksheets, saving to different file formats, or working in a server environment. This is why many developers look for an Excel library that does not require Microsoft Office.

How Does IronXL Compare?

IronXL eliminates these complications with a modern, intuitive API for Excel automation without Microsoft Office:

using IronXL;
// Create workbook without Excel
WorkBook workbook = WorkBook.Create();
WorkSheet worksheet = workbook.CreateWorkSheet("Products");
// Add data using familiar syntax
worksheet["A1"].Value = "Product";
worksheet["B1"].Value = "Price";
worksheet["A2"].Value = "Widget";
worksheet["B2"].Value = 9.99;
// Apply formatting
worksheet["A1:B1"].Style.Font.Bold = true;
worksheet["B2"].FormatString = "$#,###";
// Save with one line
workbook.SaveAs("products.xlsx");
using IronXL;
// Create workbook without Excel
WorkBook workbook = WorkBook.Create();
WorkSheet worksheet = workbook.CreateWorkSheet("Products");
// Add data using familiar syntax
worksheet["A1"].Value = "Product";
worksheet["B1"].Value = "Price";
worksheet["A2"].Value = "Widget";
worksheet["B2"].Value = 9.99;
// Apply formatting
worksheet["A1:B1"].Style.Font.Bold = true;
worksheet["B2"].FormatString = "$#,###";
// Save with one line
workbook.SaveAs("products.xlsx");
IRON VB CONVERTER ERROR developers@ironsoftware.com
$vbLabelText   $csharpLabel

How to Create Excel Files in C#: Interop vs IronXL: Figure 1 - IronXL output

IronXL allows you to create an Excel file, new workbook, and multiple worksheets programmatically. You can write data, display data, and handle XLS, XLSX, CSV, or XML files without Microsoft Excel installed or referencing the Primary Interop Assembly. This makes it a fully managed Excel library suitable for .NET Framework, .NET Core, console applications, and cross-platform environments.

Because IronXL is available via NuGet package, you can add it directly to your Visual Studio project without worrying about installing Microsoft Office. There’s no need to manage the Excel application object or release COM objects manually, reducing the risk of exceptions or warning messages. Learn more about creating Excel files with IronXL or explore Excel formulas and calculations.

Get stated with IronXL now.
green arrow pointer

How Do Other Libraries Compare?

EPPlus Implementation

EPPlus offers a clean API but requires license configuration since version 5, as discussed in Stack Overflow threads:

using OfficeOpenXml;
// Set license context (required from v5+)
ExcelPackage.License.SetNonCommercialPersonal("Test");
using (var package = new ExcelPackage())
{
    var worksheet = package.Workbook.Worksheets.Add("Products");
    worksheet.Cells[1, 1].Value = "Product";
    worksheet.Cells[1, 2].Value = "Price";
    worksheet.Cells[2, 1].Value = "Widget";
    worksheet.Cells[2, 2].Value = 9.99;
    package.SaveAs(new FileInfo("products.xlsx"));
}
using OfficeOpenXml;
// Set license context (required from v5+)
ExcelPackage.License.SetNonCommercialPersonal("Test");
using (var package = new ExcelPackage())
{
    var worksheet = package.Workbook.Worksheets.Add("Products");
    worksheet.Cells[1, 1].Value = "Product";
    worksheet.Cells[1, 2].Value = "Price";
    worksheet.Cells[2, 1].Value = "Widget";
    worksheet.Cells[2, 2].Value = 9.99;
    package.SaveAs(new FileInfo("products.xlsx"));
}
IRON VB CONVERTER ERROR developers@ironsoftware.com
$vbLabelText   $csharpLabel

How to Create Excel Files in C#: Interop vs IronXL: Figure 2 - EPPlus output

EPPlus allows you to create Excel spreadsheets, write and display data, and export to XLSX files or CSV files. However, it does not support older XLS formats, and commercial licensing is required for business use. Developers working in .NET Core or .NET Framework can integrate EPPlus via NuGet package into Visual Studio projects and console applications.

ClosedXML Approach

ClosedXML offers an open-source solution with an intuitive API:

using ClosedXML.Excel;
using (var workbook = new XLWorkbook())
{
    var worksheet = workbook.Worksheets.Add("Products");
    worksheet.Cell("A1").Value = "Product";
    worksheet.Cell("B1").Value = "Price";
    worksheet.Cell("A2").Value = "Widget";
    worksheet.Cell("B2").Value = 9.99;
    workbook.SaveAs("products.xlsx");
}
using ClosedXML.Excel;
using (var workbook = new XLWorkbook())
{
    var worksheet = workbook.Worksheets.Add("Products");
    worksheet.Cell("A1").Value = "Product";
    worksheet.Cell("B1").Value = "Price";
    worksheet.Cell("A2").Value = "Widget";
    worksheet.Cell("B2").Value = 9.99;
    workbook.SaveAs("products.xlsx");
}
IRON VB CONVERTER ERROR developers@ironsoftware.com
$vbLabelText   $csharpLabel

How to Create Excel Files in C#: Interop vs IronXL: Figure 3 - ClosedXML output

ClosedXML supports XLSX files and Excel worksheets, making it simple to create Excel sheets without Microsoft Office installed. It works across multiple worksheets, handles CSV and XML files, and integrates into .NET projects via NuGet package.

NPOI for Legacy Support

NPOI handles both XLS and XLSX formats but with a more complex API:

using NPOI.SS.UserModel;
using NPOI.XSSF.UserModel;
IWorkbook workbook = new XSSFWorkbook();
ISheet worksheet = workbook.CreateSheet("Products");
IRow headerRow = worksheet.CreateRow(0);
headerRow.CreateCell(0).SetCellValue("Product");
headerRow.CreateCell(1).SetCellValue("Price");
IRow dataRow = worksheet.CreateRow(1);
dataRow.CreateCell(0).SetCellValue("Widget");
dataRow.CreateCell(1).SetCellValue(9.99);
using (FileStream file = new FileStream("products.xlsx", FileMode.Create))
{
    workbook.Write(file);
}
using NPOI.SS.UserModel;
using NPOI.XSSF.UserModel;
IWorkbook workbook = new XSSFWorkbook();
ISheet worksheet = workbook.CreateSheet("Products");
IRow headerRow = worksheet.CreateRow(0);
headerRow.CreateCell(0).SetCellValue("Product");
headerRow.CreateCell(1).SetCellValue("Price");
IRow dataRow = worksheet.CreateRow(1);
dataRow.CreateCell(0).SetCellValue("Widget");
dataRow.CreateCell(1).SetCellValue(9.99);
using (FileStream file = new FileStream("products.xlsx", FileMode.Create))
{
    workbook.Write(file);
}
IRON VB CONVERTER ERROR developers@ironsoftware.com
$vbLabelText   $csharpLabel

How to Create Excel Files in C#: Interop vs IronXL: Figure 4 - NPOI output

NPOI allows creating Excel worksheets and workbooks programmatically, supporting multiple file formats including CSV, XLSX, and XLS files. However, its Java heritage makes the API less intuitive compared to other C# Excel libraries.

Key Decision Factors

When to Choose IronXL

IronXL excels for enterprise applications requiring cross-platform Excel library support, comprehensive Excel features, and professional support. Its intuitive API reduces development time when you need to create Excel files without Office installed, while robust performance handles large datasets efficiently. The built-in formula engine and support for multiple formats (XLS, XLSX, CSV, TSV) make it versatile for various business requirements.

Alternative Considerations

EPPlus works well for projects already using version 4.5.3 or earlier (last free version) or those with existing EPPlus commercial licenses. ClosedXML suits open-source projects with basic spreadsheet needs and no charting requirements. NPOI remains relevant when XLS support is critical and licensing costs must be minimized.

For comparison with other commercial options: GemBox.Spreadsheet offers similar features to IronXL with competitive pricing, while Aspose.Cells provides extensive functionality at a premium price point. However, IronXL's combination of features, performance, and support often provides the best value for Excel manipulation .NET projects.

Migration from Interop to IronXL

Migrating from Excel Interop to IronXL follows a straightforward pattern. For detailed guidance, see the IronXL documentation and explore code examples:

  1. Remove COM references - Replace Microsoft.Office.Interop.Excel references with IronXL
  2. Simplify object creation - Replace Application/Workbook/Worksheet hierarchy with direct WorkBook creation
  3. Update cell access - Convert from Cells[row, col] to worksheet["A1"] notation
  4. Remove cleanup code - Eliminate Marshal.ReleaseComObject calls
  5. Test cross-platform - Verify functionality on target deployment platforms

For complex migrations involving Excel charts or conditional formatting, IronXL provides comprehensive support.

Understanding the Limitations

It's important to note that Primary Interop Assemblies (PIAs) cannot function without Excel installed—they're merely interfaces to COM objects that require the actual Office application. This misconception often leads to deployment failures when moving applications to servers or attempting Excel automation without Office installation.

Regarding security, IronXL undergoes regular security audits and maintains DigiCert certification, providing enterprise-grade protection without the vulnerabilities associated with COM interfaces. For detailed security information, visit the IronXL security documentation.

Conclusion

While Excel Interop served its purpose in desktop applications, modern development demands more flexible alternatives to the Excel library. IronXL provides the most comprehensive alternative for creating Excel files without Interop, combining ease of use with enterprise features and cross-platform Excel support.

Whether you're building cloud applications, working with Docker containers, or developing cross-platform solutions, selecting a library that doesn't require Excel installation is crucial for creating scalable and maintainable applications. Download IronXL to transform your Excel automation workflow today.

Start using IronXL in your project today with a free trial.

First Step:
green arrow pointer

Frequently Asked Questions

What are some limitations of using Excel Interop in C#?

Excel Interop in C# can be limited by its dependence on Microsoft Excel installations, potential performance issues, and lack of cross-platform support. IronXL offers a more efficient and versatile alternative for spreadsheet manipulation.

Why should I consider using IronXL over Excel Interop?

IronXL provides a more robust solution with its cross-platform capabilities, faster performance, and reduced memory usage. It doesn't require Excel to be installed on the server, making it more suitable for server-side applications.

Can IronXL handle large datasets efficiently?

Yes, IronXL is optimized to handle large datasets efficiently. It provides better performance and memory management compared to Excel Interop, making it ideal for processing extensive data.

Is IronXL compatible with .NET Core?

IronXL is fully compatible with .NET Core, allowing developers to create applications that work across various platforms without relying on Microsoft Excel installations.

What are the licensing options for IronXL?

IronXL offers flexible licensing options, including single developer, team, and enterprise licenses, making it suitable for different project sizes and budgets.

Does IronXL support exporting data to Excel formats?

IronXL supports exporting data to multiple Excel formats, such as XLS, XLSX, and CSV, providing flexibility for various data manipulation and presentation needs.

Can I use IronXL for automated Excel report generation?

Yes, IronXL is designed to facilitate automated Excel report generation, offering features like data filtering, chart creation, and formula processing to streamline reporting tasks.

How does IronXL ensure data accuracy during Excel operations?

IronXL ensures data accuracy with its reliable formula processing and cell formatting capabilities, minimizing errors and maintaining data integrity during Excel operations.

What programming languages are supported by IronXL?

IronXL is primarily designed for use with C#, but it also supports other .NET languages, making it versatile for developers working within the .NET ecosystem.

Does IronXL offer customer support?

IronXL provides comprehensive customer support, including documentation, tutorials, and direct assistance, ensuring developers can effectively utilize the library in their projects.

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