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

常见问题解答

如何在 C# 中将 XLSX 文件转换为 CSV?

要使用 IronXL 将 XLSX 文件转换为 CSV,首先通过 NuGet 包管理器安装库,使用 Install-Package IronXL.Excel。接着,使用 IronXL 的方法加载 Excel 文件,必要时修改工作簿,然后将其导出为 CSV 文件。

使用 IronXL 可以导出哪些文件格式?

IronXL 允许将 Excel 文件导出为多种格式,包括 CSV、JSON、XML、XLS 和 XLSX,从而实现灵活的数据处理和集成。

是否必须安装Microsoft Excel才能使用IronXL?

不需要,IronXL 独立于 Microsoft Excel 运作,允许您进行 Excel 文件转换而无需在系统上安装 Excel。

如何在 C# 中将 Excel 工作簿转换为数据集?

您可以使用 IronXL 将 Excel 工作簿转换为数据集,方法是加载工作簿并利用库的方法将其转换为数据集,以便与 DataGridView 等工具集成。

在哪里可以找到 IronXL 的 API 参考文档?

IronXL 的 API 参考文档可在 IronXL 网站上获取,提供关于以编程方式处理 Excel 文件的全面指南。

如何在 C# 项目中安装 IronXL 库?

您可以使用 Visual Studio 中的 NuGet 包管理器安装 IronXL 库。在 NuGet 包管理器控制台中使用命令 Install-Package IronXL.Excel

IronXL 能将 Excel 文件转换为 JSON 和 XML 格式吗?

是的,IronXL 可以通过库的导出函数将 Excel 文件转换为 JSON 和 XML 格式,及其他格式。

如果我的 Excel 转 CSV 转换失败,常见的故障排除步骤是什么?

确保 IronXL 已正确安装以及您的代码准确引用了库的方法。验证 Excel 文件是否可访问且未损坏。查阅 IronXL API 文档以获取更多故障排除提示。

Curtis Chau
技术作家

Curtis Chau 拥有卡尔顿大学的计算机科学学士学位,专注于前端开发,精通 Node.js、TypeScript、JavaScript 和 React。他热衷于打造直观且美观的用户界面,喜欢使用现代框架并创建结构良好、视觉吸引力强的手册。

除了开发之外,Curtis 对物联网 (IoT) 有浓厚的兴趣,探索将硬件和软件集成的新方法。在空闲时间,他喜欢玩游戏和构建 Discord 机器人,将他对技术的热爱与创造力相结合。

准备开始了吗?
Nuget 下载 1,686,155 | 版本: 2025.11 刚刚发布