How to Convert XLSX to CSV, JSON, XML and more in C#

This article was translated from English: Does it need improvement?
Translated
View the article in English

IronXL can convert any Excel file into various formats.

These formats include: JSON, CSV, XML, and even older Excel formats such as XLS.

This brief article will show you how to use IronXL to convert to XML, convert to CSV, convert to JSON, and as a bonus, show you how to output an Excel worksheet as a dataset.

Quickstart: Convert an XLSX file to CSV with one line

This simple example shows how effortlessly IronXL lets you convert an existing Excel workbook into a CSV file in just one line. No manual parsing—just load your workbook and save it directly as CSV to get started immediately.

Nuget IconGet started making PDFs with NuGet now:

  1. Install IronXL with NuGet Package Manager

    PM > Install-Package IronXL.Excel

  2. Copy and run this code snippet.

    IronXL.WorkBook.Load("input.xlsx").SaveAsCsv("output.csv");
  3. Deploy to test on your live environment

    Start using IronXL in your project today with a free trial
    arrow pointer

Step 1

1. Install the IronXL Library Free

First, you must have IronXL installed before you can use it in your applications. The following two methods allow you to install IronXL.

Download: https://ironsoftware.com/csharp/excel/docs/

Or use the NuGet Package Manager

  • Right-click the Solution name in Solution Explorer
  • Click Manage NuGet Packages
  • Browse for IronXL.Excel
  • Install
Install-Package IronXL.Excel

How to Tutorial

2. Convert to XML, JSON, CSV, XLS

Now you are ready.

Add the following code:

:path=/static-assets/excel/content-code-examples/how-to/csharp-convert-xlsx-csv-convert.cs
using IronXL;

// Load an existing Excel workbook
WorkBook workbook = WorkBook.Load("Normal_Excel_File.xlsx");

// Set metadata title for the workbook
workbook.Metadata.Title = "Normal_Excel_File.xlsx";

// Save the workbook in different formats
workbook.SaveAs("XLS_Export.xls");
workbook.SaveAs("XLSX_Export.xlsx");
workbook.SaveAsCsv("CSV_Export.csv");
workbook.SaveAsJson("JSON_Export.json");
workbook.SaveAsXml("XML_Export.xml");

// Convert the workbook to a DataSet, allowing integration with other data tools like DataGridView
System.Data.DataSet dataSet = workbook.ToDataSet();
IRON VB CONVERTER ERROR developers@ironsoftware.com
$vbLabelText   $csharpLabel

The code above loads an ordinary XLSX file, adds a Title, then converts it to several formats. Lastly, it exports the Worksheet as a DataSet that gets used by a DataGridView object.

The various files exported are shown below.

CSV File Export
Figure 1 - CSV File Export
XML Export
Figure 2 - XML Export
JSON Export
Figure 3 - JSON Export
XLS Export
Figure 4 - XLS Export
Excel Input for all exports
Figure 5 - Excel Input for all exports

Library Quick Access

IronXL API Reference Documentation

Learn more and share how to merge, unmerge, and work with cells in Excel spreadsheets using the handy IronXL API Reference Documentation.

IronXL API Reference Documentation
Documentation related to 2. Convert to XML, JSON, CSV, XLS

Questions Fréquemment Posées

Comment puis-je convertir un fichier XLSX en CSV en C# ?

Pour convertir un fichier XLSX en CSV en utilisant IronXL, installez d'abord la bibliothèque via le Gestionnaire de Packages NuGet avec Install-Package IronXL.Excel. Ensuite, chargez le fichier Excel en utilisant les méthodes de IronXL, modifiez le classeur si nécessaire, et exportez-le en fichier CSV.

Quels formats de fichier peuvent être exportés en utilisant IronXL ?

IronXL permet d'exporter les fichiers Excel en plusieurs formats, y compris CSV, JSON, XML, XLS, et XLSX, permettant une gestion et une intégration flexibles des données.

Est-il nécessaire d'avoir Microsoft Excel installé pour utiliser IronXL ?

Non, IronXL fonctionne indépendamment de Microsoft Excel, vous permettant de réaliser des conversions de fichiers Excel sans avoir besoin d'installer Excel sur votre système.

Comment convertir un classeur Excel en DataSet en C# ?

Vous pouvez convertir un classeur Excel en DataSet en utilisant IronXL en chargeant le classeur et en utilisant la méthode de la bibliothèque pour le transformer en DataSet, facilitant l'intégration avec des outils comme DataGridView.

Où puis-je trouver la Documentation de Référence de l'API pour IronXL ?

La Documentation de Référence de l'API pour IronXL est disponible sur le site IronXL, fournissant des conseils complets sur la gestion des fichiers Excel par programmation.

Comment puis-je installer la bibliothèque IronXL dans un projet C# ?

Vous pouvez installer la bibliothèque IronXL en utilisant le Gestionnaire de Packages NuGet dans Visual Studio. Utilisez la commande Install-Package IronXL.Excel dans la Console du Gestionnaire de Packages NuGet.

IronXL peut-il convertir des fichiers Excel aux formats JSON et XML ?

Oui, IronXL peut convertir des fichiers Excel en formats JSON et XML, entre autres, en utilisant les fonctions d'exportation de la bibliothèque.

Quelles sont les étapes communes de dépannage si ma conversion Excel en CSV échoue ?

Assurez-vous que IronXL est correctement installé et que votre code référence précisément les méthodes de la bibliothèque. Vérifiez que le fichier Excel est accessible et non corrompu. Consultez la documentation de l'API IronXL pour des conseils de dépannage supplémentaires.

Curtis Chau
Rédacteur technique

Curtis Chau détient un baccalauréat en informatique (Université de Carleton) et se spécialise dans le développement front-end avec expertise en Node.js, TypeScript, JavaScript et React. Passionné par la création d'interfaces utilisateur intuitives et esthétiquement plaisantes, Curtis aime travailler avec des frameworks modernes ...

Lire la suite
Prêt à commencer?
Nuget Téléchargements 1,686,155 | Version : 2025.11 vient de sortir