C# Write to Excel [Without Using Interop] Code Example Tutorial
Follow step-by-step examples of how to create, open, and save Excel files with C#, and apply basic operations like getting sum, average, count, and more. IronXL.Excel is a stand-alone .NET software library for reading a wide range of spreadsheet formats. It does not require Microsoft Excel to be installed, nor depends on Interop.
Quickstart: Create, Write & Save Excel in a Snap
Ready to generate Excel files in under a minute? This example uses IronXL to create a workbook, write a value to a cell, and save the file—all with minimal fuss and zero reliance on Interop. It's the fastest way to get started with Excel file operations in C#.
Get started making PDFs with NuGet now:
Install IronXL with NuGet Package Manager
Copy and run this code snippet.
var workbook = IronXL.WorkBook.Create(IronXL.ExcelFileFormat.XLSX); workbook.CreateWorkSheet("Data")["A1"].Value = "Fast Start"; workbook.SaveAs("quick.xlsx");Deploy to test on your live environment
Minimal Workflow (5 steps)
- Download the Write Excel C# Library
- Create and open a new CSV or XML Excel file as an Excel workbook
- Save and export your Excel workbook
- Apply Advanced Operations in your multiple Excel worksheets
- Integrate with Excel Database
Overview
Use IronXL to Open and Write Excel Files
Open, write, save, and customize Excel files with the easy-to-use IronXL C# library.
Download a sample project from GitHub or use your own, and follow the tutorial.
- Install the IronXL Excel Library from NuGet or the DLL download
- Use the
WorkBook.Loadmethod to read any XLS, XLSX, or CSV document. - Get Cell values using intuitive syntax:
sheet["A11"].DecimalValue
In this tutorial, we will walk you through:
- Installing IronXL.Excel: how to install IronXL.Excel to an existing project.
- Basic Operations: basic operation steps with Excel to Create or Open workbook, select sheet, select cell, and save the workbook.
- Advanced Sheet Operations: how to utilize different manipulation capabilities like adding headers or footers, mathematical operations, and other features.
Open an Excel File: Quick Code
:path=/static-assets/excel/content-code-examples/tutorials/csharp-open-write-excel-file-1.cs
using IronXL;
WorkBook workBook = WorkBook.Load("test.xlsx");
WorkSheet workSheet = workBook.DefaultWorkSheet;
IronXL.Range range = workSheet["A2:A8"];
decimal total = 0;
// iterate over range of cells
foreach (var cell in range)
{
Console.WriteLine("Cell {0} has value '{1}'", cell.RowIndex, cell.Value);
if (cell.IsNumeric)
{
// Get decimal value to avoid floating numbers precision issue
total += cell.DecimalValue;
}
}
// Check formula evaluation
if (workSheet["A11"].DecimalValue == total)
{
Console.WriteLine("Basic Test Passed");
}
Imports IronXL
Private workBook As WorkBook = WorkBook.Load("test.xlsx")
Private workSheet As WorkSheet = workBook.DefaultWorkSheet
Private range As IronXL.Range = workSheet("A2:A8")
Private total As Decimal = 0
' iterate over range of cells
For Each cell In range
Console.WriteLine("Cell {0} has value '{1}'", cell.RowIndex, cell.Value)
If cell.IsNumeric Then
' Get decimal value to avoid floating numbers precision issue
total += cell.DecimalValue
End If
Next cell
' Check formula evaluation
If workSheet("A11").DecimalValue = total Then
Console.WriteLine("Basic Test Passed")
End If
Write and Save Changes to the Excel File: Quick Code
:path=/static-assets/excel/content-code-examples/tutorials/csharp-open-write-excel-file-2.cs
workSheet["B1"].Value = 11.54;
// Save Changes
workBook.SaveAs("test.xlsx");
workSheet("B1").Value = 11.54
' Save Changes
workBook.SaveAs("test.xlsx")
Step 1
1. Install the IronXL C# Library FREE
Commencez à utiliser IronXL dans votre projet aujourd'hui avec un essai gratuit.
IronXL.Excel provides a flexible and powerful library for opening, reading, editing, and saving Excel files in .NET. It can be installed and used on all of the .NET project types, like Windows applications, ASP.NET MVC, and .NET Core Application.
Install the Excel Library to your Visual Studio Project with NuGet
The first step will be to install IronXL.Excel. To add the IronXL.Excel library to the project, we have two ways: NuGet Package Manager or NuGet Package Manager Console.
To add IronXL.Excel library to our project using NuGet, we can do it using a visualized interface, NuGet Package Manager:
- Using mouse -> right-click on project name -> Select manage NuGet Package

- From the browse tab -> search for IronXL.Excel -> Install

- And we are done

Install Using NuGet Package Manager Console
- From tools -> NuGet Package Manager -> Package Manager Console

- Run command
Install-Package IronXL.Excel

Manually Install with the DLL
You may also choose to manually install the DLL to your project or to your global assembly cache.
How To Tutorials
2. Basic Operations: Create, Open, Save
2.1. Sample Project: HelloWorld Console Application
Create a HelloWorld Project in Visual Studio.
- Open Visual Studio

- Choose Create New Project

- Choose Console App (.NET framework)

- Give the sample the name “HelloWorld” and click create

- Now the console application is created

- Add IronXL.Excel to your project -> click install

- Add code to read the first cell in the first sheet from an Excel file and print it
using IronXL;
var workbook = WorkBook.Load("example.xlsx");
var sheet = workbook.DefaultWorkSheet;
Console.WriteLine(sheet["A1"].Text);
using IronXL;
var workbook = WorkBook.Load("example.xlsx");
var sheet = workbook.DefaultWorkSheet;
Console.WriteLine(sheet["A1"].Text);
Imports IronXL
Private workbook = WorkBook.Load("example.xlsx")
Private sheet = workbook.DefaultWorkSheet
Console.WriteLine(sheet("A1").Text)
...
Further Reading
To learn more about working with IronXL, you may wish to look at other tutorials within this section and also the examples on our homepage, which most developers find sufficient to get started.
Our API Reference contains specific references to the WorkBook class.
Questions Fréquemment Posées
Comment puis-je ouvrir un fichier Excel en C# sans utiliser Interop ?
Vous pouvez utiliser la méthode WorkBook.Load de IronXL pour ouvrir des fichiers XLS, XLSX ou CSV en C# sans avoir besoin de Microsoft Excel ou Interop.
Quelles sont les étapes pour écrire des données dans un fichier Excel en C#?
Pour écrire des données dans un fichier Excel en C#, utilisez IronXL pour créer un classeur et une feuille de calcul, définissez des valeurs dans des cellules spécifiques en utilisant worksheet["A1"].Value = "Votre Valeur", et enregistrez le classeur avec la méthode SaveAs.
Comment puis-je manipuler des feuilles Excel en utilisant IronXL?
Avec IronXL, vous pouvez ajouter, renommer ou supprimer des feuilles, définir des en-têtes et pieds de page, et effectuer des calculs mathématiques directement sur les données de la feuille de calcul.
Est-il possible de lire les valeurs des cellules d'un fichier Excel en utilisant C#?
Oui, en utilisant IronXL, vous pouvez lire les valeurs des cellules avec une syntaxe comme sheet["A1"].Text pour récupérer le texte d'une cellule spécifique dans un fichier Excel.
Comment installer IronXL dans un projet .NET ?
Vous pouvez installer IronXL dans votre projet .NET en utilisant le gestionnaire de packages NuGet en recherchant IronXL.Excel ou en utilisant la commande de la console du gestionnaire de packages Install-Package IronXL.Excel.
IronXL peut-il être utilisé dans les projets ASP.NET MVC?
Oui, IronXL est compatible avec les projets ASP.NET MVC, vous permettant de gérer les opérations sur les fichiers Excel au sein de vos applications web.
Quels formats de fichiers IronXL prend-il en charge pour les opérations Excel?
IronXL prend en charge la lecture et l'écriture de formats Excel tels que XLS, XLSX et CSV, permettant une gestion flexible des données dans les applications C#.
Où puis-je trouver des exemples de code pour utiliser IronXL?
Des exemples de code pour l'utilisation de IronXL peuvent être trouvés dans le tutoriel sur le site Web de IronXL et dans les projets d'exemple disponibles sur GitHub.
Quels sont les avantages à utiliser IronXL pour la manipulation de fichiers Excel?
IronXL permet aux développeurs de gérer les fichiers Excel en C# sans avoir besoin de Microsoft Excel ou Interop, offrant une API simple pour créer, lire et modifier des documents Excel.

