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

Preguntas Frecuentes

¿Cómo puedo convertir un archivo XLSX a CSV en C#?

Para convertir un archivo XLSX a CSV usando IronXL, primero instala la biblioteca a través del Administrador de Paquetes NuGet con Install-Package IronXL.Excel. Luego, carga el archivo de Excel usando los métodos de IronXL, modifica el libro de trabajo si es necesario, y expórtalo a un archivo CSV.

¿Qué formatos de archivo se pueden exportar usando IronXL?

IronXL permite exportar archivos de Excel a varios formatos, incluyendo CSV, JSON, XML, XLS y XLSX, permitiendo una gestión de datos e integración flexibles.

¿Es necesario tener instalado Microsoft Excel para usar IronXL?

No, IronXL opera de forma independiente de Microsoft Excel, lo que te permite realizar conversiones de archivos de Excel sin necesitar Excel instalado en tu sistema.

¿Cómo convierto un libro de Excel a un DataSet en C#?

Puedes convertir un libro de Excel a un DataSet usando IronXL al cargar el libro y utilizar el método de la biblioteca para transformarlo en un DataSet, facilitando la integración con herramientas como DataGridView.

¿Dónde puedo encontrar la Documentación de Referencia del API para IronXL?

La Documentación de Referencia del API para IronXL está disponible en el sitio web de IronXL, proporcionando una guía completa sobre cómo manejar archivos de Excel programáticamente.

¿Cómo puedo instalar la biblioteca IronXL en un proyecto de C#?

Puedes instalar la biblioteca IronXL usando el Administrador de Paquetes NuGet en Visual Studio. Usa el comando Install-Package IronXL.Excel en la Consola del Administrador de Paquetes NuGet.

¿Puede IronXL convertir archivos de Excel a formatos JSON y XML?

Sí, IronXL puede convertir archivos de Excel en formatos JSON y XML, entre otros, usando las funciones de exportación de la biblioteca.

¿Cuáles son los pasos comunes de resolución de problemas si mi conversión de Excel a CSV falla?

Asegúrate de que IronXL esté correctamente instalado y que tu código refiera con precisión los métodos de la biblioteca. Verifica que el archivo de Excel sea accesible y no esté corrupto. Consulta la documentación del API de IronXL para obtener más consejos de resolución de problemas.

Curtis Chau
Escritor Técnico

Curtis Chau tiene una licenciatura en Ciencias de la Computación (Carleton University) y se especializa en el desarrollo front-end con experiencia en Node.js, TypeScript, JavaScript y React. Apasionado por crear interfaces de usuario intuitivas y estéticamente agradables, disfruta trabajando con frameworks modernos y creando manuales bien ...

Leer más
¿Listo para empezar?
Nuget Descargas 1,686,155 | Versión: 2025.11 recién lanzado