Skip to footer content

How to Create an Excel File in C# using IronXL

In this tutorial, learn to create Excel files in C# using IronXL, a library that supports the latest .NET framework versions. Start by installing IronXL via NuGet Package Manager. Import IronXL into your program file, allowing access to its features. Create a workbook using Workbook.Create, with XLSX as the default format. Add sheets and set cell values or formulas programmatically. Customize cell styling, including borders and background colors. Assign values and properties to cell ranges. Enhance text with different font styles and sizes. Implement formulas with ease and protect sheets from editing. Finally, save the Excel file using the Save As function. IronXL simplifies Excel operations without requiring Microsoft Excel or Excel Interop on your server, making it a versatile tool for developers.

Key Points:

  • Workbook.Create(): Initiates a new Excel workbook.
  • sheet["A1"].Value: Set cell value directly.
  • sheet["B1"].Formula: Assign a formula to a cell.
  • cell.Style: Customize cell appearance by modifying its style properties.
  • sheet.Protect(): Protect the sheet to prevent editing.
  • workbook.SaveAs(): Save the workbook to a file.

Further Reading: IronXL Documentation

Regan Pun
Software Engineer
Regan graduated from the University of Reading, with a BA in Electronic Engineering. Before joining Iron Software, his previous job roles had him laser-focused on single tasks; and what he most enjoys at Iron Software is the spectrum of work he gets to undertake, whether it’s adding value to sales, technical support, product development or marketing. He enjoys understanding the way developers are using the Iron Software library, and using that knowledge to continually improve documentation and develop the products.