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.
Get started making PDFs with NuGet now:
Install IronXL with NuGet Package Manager
Copy and run this code snippet.
IronXL.WorkBook.Load("input.xlsx").SaveAsCsv("output.csv");Deploy to test on your live environment
Minimal Workflow (5 steps)
- Download C# library to convert XLSX to CSV
- Load existing XLSX Excel spreadsheet
- Access or modify the workbook
- Export to CSV file or several other formats including JSON, TSV, and XML
- Check the output files and apply further processing
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.csusing 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.comThe 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.comFor 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.comThe various exported files are shown below.
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 DocumentationFrequently 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.











