How to Convert XLSX to CSV, JSON, XML and more in C#
Published: 2022-02-28 03:51:16

---
canonical_url: https://ironsoftware.com/csharp/excel/docs/questions/csharp-convert-xlsx-to-csv
---

IronXL can convert any Excel file into various formats.

These formats include: JSON, CSV, XML and even older the Excel format 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.

**C#:**
```
using IronXL;
private void button7_Click(object sender, EventArgs e)
{
    WorkBook workbook = WorkBook.Load("Normal_Excel_File.xlsx");
    workbook.Metadata.Title = "Normal_Excel_File.xlsx";
    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");
    System.Data.DataSet dataSet = workbook.ToDataSet();
    dataGridView1.DataSource = dataSet;
    dataGridView1.DataMember = "Sheet1";
}
```

**VB:**
```
Imports IronXL
Private Sub button7_Click(ByVal sender As Object, ByVal e As EventArgs)
	Dim workbook As WorkBook = WorkBook.Load("Normal_Excel_File.xlsx")
	workbook.Metadata.Title = "Normal_Excel_File.xlsx"
	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")
	Dim dataSet As System.Data.DataSet = workbook.ToDataSet()
	dataGridView1.DataSource = dataSet
	dataGridView1.DataMember = "Sheet1"
End Sub
```

---

**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/](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

`PM> Install-Package IronPdf`

---

**How to Tutorial**

## 2. Convert to XML, JSON, CSV, XLS

Now you are ready.

Add the following code:

**C#:**
```
using IronXL;
private void button7_Click(object sender, EventArgs e)
{
    WorkBook workbook = WorkBook.Load("Normal_Excel_File.xlsx");
    workbook.Metadata.Title = "Normal_Excel_File.xlsx";
    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");
    System.Data.DataSet dataSet = workbook.ToDataSet();
    dataGridView1.DataSource = dataSet;
    dataGridView1.DataMember = "Sheet1";
}
```

**VB:**
```
Imports IronXL
Private Sub button7_Click(ByVal sender As Object, ByVal e As EventArgs)
	Dim workbook As WorkBook = WorkBook.Load("Normal_Excel_File.xlsx")
	workbook.Metadata.Title = "Normal_Excel_File.xlsx"
	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")
	Dim dataSet As System.Data.DataSet = workbook.ToDataSet()
	dataGridView1.DataSource = dataSet
	dataGridView1.DataMember = "Sheet1"
End Sub
```

The code above Loads an ordinary XLSX file, adds a Title, then converts 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.

![Image 1](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/9mbq63x1nyv4r63qo5wp.png)

**Figure 1** - _CSV File Export_

![Image 2](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/z1fwlt2zel6zpc255rlq.png)

**Figure 2** - _XML Export_

![Image 3](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/bgn4ehubtxblx36x1erz.png)

**Figure 3** - _JSON Export_

![Image 4](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/jmqm0qzdmx3bl4y94qth.png)

**Figure 4** - _XLS Export_

![Image 5](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/ww90yg5nmrszpmrqqunn.png)

**Figure 5** - _Excel Input for all exports_

---