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

IronXL converts Excel files to multiple formats including JSON, CSV, XML, and older Excel formats like XLS, using simple one-line commands that eliminate manual parsing.

IronXL converts any Excel file into various formats, providing developers with tools to work with Excel in C# without Interop. Whether migrating data between systems, creating data exports for web applications, or integrating with legacy systems, IronXL simplifies the conversion process.

These formats include: JSON for modern web APIs, CSV for data interchange, XML for structured data storage, and older Excel formats such as XLS for backward compatibility. Each format serves specific use cases—CSV works well for database imports, JSON integrates with REST APIs, and XML maintains hierarchical data relationships.

This article demonstrates how to use IronXL to convert to XML, CSV, JSON, and export Excel worksheets as datasets for direct integration with .NET data controls.

Quickstart: Convert an XLSX file to CSV with one line

This example shows how IronXL converts an existing Excel workbook into a CSV file in one line. 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

How Do I Install the IronXL Library?

First, install IronXL before using it in your applications. IronXL supports .NET MAUI, Blazor, and traditional .NET applications. Use either of these installation methods:

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

How Can I Convert Excel Files to Different Formats?

IronXL provides conversion capabilities that handle complex parsing and formatting automatically.

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 XLSX file, adds a Title, then converts it to several formats. When converting to CSV, IronXL handles special characters, multi-line cells, and proper escaping. For JSON exports, it creates a structured object representation of your spreadsheet data. XML conversion preserves cell formatting and data types. Finally, it exports the Worksheet as a DataSet for use with DataGridView objects, which works well when working with DataTables.

Here's another example showing how to convert specific worksheets with custom options:

using IronXL;

// Load workbook and select specific worksheet
WorkBook workbook = WorkBook.Load("MultiSheet.xlsx");
WorkSheet sheet = workbook.WorkSheets["SalesData"];

// Convert just one worksheet to CSV with custom delimiter
sheet.SaveAsCsv("SalesData.csv", delimiter: ";");

// Export to JSON with formatting preserved
var jsonOptions = new JsonSaveOptions
{
    PreserveFormatting = true,
    IncludeHeaders = true
};
sheet.SaveAsJson("SalesData.json", jsonOptions);

// Convert to XML with custom root element
sheet.SaveAsXml("SalesData.xml", "SalesReport");
using IronXL;

// Load workbook and select specific worksheet
WorkBook workbook = WorkBook.Load("MultiSheet.xlsx");
WorkSheet sheet = workbook.WorkSheets["SalesData"];

// Convert just one worksheet to CSV with custom delimiter
sheet.SaveAsCsv("SalesData.csv", delimiter: ";");

// Export to JSON with formatting preserved
var jsonOptions = new JsonSaveOptions
{
    PreserveFormatting = true,
    IncludeHeaders = true
};
sheet.SaveAsJson("SalesData.json", jsonOptions);

// Convert to XML with custom root element
sheet.SaveAsXml("SalesData.xml", "SalesReport");
IRON VB CONVERTER ERROR developers@ironsoftware.com
$vbLabelText   $csharpLabel

For advanced scenarios, you can export to multiple formats simultaneously or handle large files efficiently:

using IronXL;
using System.Threading.Tasks;

// Async conversion for large files
public async Task ConvertLargeFileAsync(string inputPath)
{
    WorkBook workbook = WorkBook.Load(inputPath);

    // Parallel export to multiple formats
    var tasks = new[]
    {
        Task.Run(() => workbook.SaveAsCsv("output.csv")),
        Task.Run(() => workbook.SaveAsJson("output.json")),
        Task.Run(() => workbook.SaveAsXml("output.xml"))
    };

    await Task.WhenAll(tasks);
}
using IronXL;
using System.Threading.Tasks;

// Async conversion for large files
public async Task ConvertLargeFileAsync(string inputPath)
{
    WorkBook workbook = WorkBook.Load(inputPath);

    // Parallel export to multiple formats
    var tasks = new[]
    {
        Task.Run(() => workbook.SaveAsCsv("output.csv")),
        Task.Run(() => workbook.SaveAsJson("output.json")),
        Task.Run(() => workbook.SaveAsXml("output.xml"))
    };

    await Task.WhenAll(tasks);
}
IRON VB CONVERTER ERROR developers@ironsoftware.com
$vbLabelText   $csharpLabel

The various exported files are shown below.

CSV file export showing comma-separated values in a text editor with properly escaped data
Figure 1 - CSV File Export
XML export displaying hierarchical structure with properly formatted elements and attributes representing Excel data
Figure 2 - XML Export
JSON export showing structured data in JavaScript object notation format with proper nesting and data types
Figure 3 - JSON Export
XLS export opened in Microsoft Excel showing compatibility with older Excel format while preserving formatting
Figure 4 - XLS Export
Original Excel XLSX file showing source data with multiple columns and formatting before conversion to various formats
Figure 5 - Excel Input for all exports

Each conversion format serves different purposes in modern applications. CSV files work well for importing data into databases or data analysis tools. JSON format suits web APIs and JavaScript applications. XML maintains data structure and is commonly used in enterprise systems. The legacy XLS format ensures compatibility with older Excel versions and systems that require backward compatibility.

When working with these conversions, IronXL handles many complexities automatically:

  • Character Encoding: Proper UTF-8 encoding for international characters
  • Data Type Preservation: Maintains numeric, date, and text formatting
  • Formula Evaluation: Calculates formula results before export
  • Large File Handling: Efficient memory usage for big spreadsheets
  • Error Handling: Graceful handling of corrupted or protected files

For applications requiring high performance or dealing with file size limits, IronXL provides optimization options. You can integrate these conversions into automated workflows, web services, or desktop applications.


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 How Can I Convert Excel Files to Different Formats?

Frequently Asked Questions

How do I convert XLSX to CSV in C# without Excel installed?

IronXL allows you to convert XLSX to CSV with a single line of code: IronXL.WorkBook.Load("input.xlsx").SaveAsCsv("output.csv"). This works without needing Microsoft Excel or Interop installed on your system.

What file formats can I convert Excel files to using C#?

IronXL supports converting Excel files to multiple formats including CSV, JSON, XML, TSV, and older Excel formats like XLS. Each format is ideal for different use cases - CSV for database imports, JSON for REST APIs, and XML for maintaining hierarchical data structures.

How do I install the Excel conversion library for C#?

Install IronXL using NuGet Package Manager by searching for 'IronXL.Excel' or via the Package Manager Console with the command 'Install-Package IronXL'. The library supports .NET MAUI, Blazor, and traditional .NET applications.

Can I convert Excel to JSON for use with web APIs?

Yes, IronXL provides built-in conversion from Excel to JSON format, making it easy to integrate Excel data with modern web APIs and REST services. The conversion handles complex data structures automatically.

Does the Excel conversion handle special characters and formatting?

IronXL automatically handles special characters, multi-line cells, and proper escaping when converting Excel files to formats like CSV. This eliminates the need for manual parsing or formatting corrections.

Curtis Chau
Technical Writer

Curtis Chau holds a Bachelor’s degree in Computer Science (Carleton University) and specializes in front-end development with expertise in Node.js, TypeScript, JavaScript, and React. Passionate about crafting intuitive and aesthetically pleasing user interfaces, Curtis enjoys working with modern frameworks and creating well-structured, visually appealing manuals.

...

Read More
Ready to Get Started?
Nuget Downloads 1,753,501 | Version: 2025.12 just released