Introduction
IronXL supports the conversion of spreadsheet files between various formats, including XLS, XLSX, XLSM, XLTX, CSV, TSV, JSON, XML, and HTML. It also provides support for inline code data types such as HTML string, Binary, Byte array, Data set, and Memory stream. The Load
method is used to open a spreadsheet file, and the SaveAs
method is used to export the spreadsheet to the desired file type.
How to Convert and Export (XLSX, XLS, XLSM, XLTX, CSV) in C#

- Install the C# library for converting Excel files to other file formats
- Use the
WorkBook
class to load or create new XLS or XLSX - View, add, or modify data in the Excel spreadsheet using C#
- Utilize the methods in the
WorkBook
class to export the spreadsheet - Check the exported file in the specified directory
Get started with IronXL
Start using IronXL in your project today with a free trial.
Convert Spreadsheet Type Example
The process of converting spreadsheet types involves loading a file in one supported format and exporting it to another format using IronXL's intelligent data restructuring capabilities.
While the SaveAs
method can be used to export to CSV, JSON, XML, and HTML, it is recommended to use the dedicated methods for each file format:
SaveAsCsv
SaveAsJson
SaveAsXml
ExportToHtml
Please note
fileName.sheetName.format
. In the example below, the output for the CSV format would be sample.new_sheet.csv
.// Example C# code to convert an Excel spreadsheet to different formats using IronXL
using IronXL;
class SpreadsheetConversion
{
static void Main()
{
// Load the Excel spreadsheet
WorkBook workbook = WorkBook.Load("sample.xlsx");
// Convert and save as CSV
workbook.SaveAsCsv("sample.csv");
// Convert and save as JSON
workbook.SaveAsJson("sample.json");
// Convert and save as XML
workbook.SaveAsXml("sample.xml");
// Convert and export to HTML
workbook.ExportToHtml("sample.html");
// The files will be saved in the project's directory with the specified formats
}
}
// Example C# code to convert an Excel spreadsheet to different formats using IronXL
using IronXL;
class SpreadsheetConversion
{
static void Main()
{
// Load the Excel spreadsheet
WorkBook workbook = WorkBook.Load("sample.xlsx");
// Convert and save as CSV
workbook.SaveAsCsv("sample.csv");
// Convert and save as JSON
workbook.SaveAsJson("sample.json");
// Convert and save as XML
workbook.SaveAsXml("sample.xml");
// Convert and export to HTML
workbook.ExportToHtml("sample.html");
// The files will be saved in the project's directory with the specified formats
}
}
' Example C# code to convert an Excel spreadsheet to different formats using IronXL
Imports IronXL
Friend Class SpreadsheetConversion
Shared Sub Main()
' Load the Excel spreadsheet
Dim workbook As WorkBook = WorkBook.Load("sample.xlsx")
' Convert and save as CSV
workbook.SaveAsCsv("sample.csv")
' Convert and save as JSON
workbook.SaveAsJson("sample.json")
' Convert and save as XML
workbook.SaveAsXml("sample.xml")
' Convert and export to HTML
workbook.ExportToHtml("sample.html")
' The files will be saved in the project's directory with the specified formats
End Sub
End Class
Advanced
In the previous section, we explored the most common file formats for conversion. However, IronXL has the capability to convert spreadsheets to many more formats. Explore all the available options for loading and exporting spreadsheets.
Load
- XLS, XLSX, XLSM, and XLTX
- CSV
- TSV
Export
- XLS, XLSX, and XLSM
- CSV and TSV
- JSON
- XML
- HTML
-
Inline code data types:
- HTML string
- Binary and Byte array
- Data set: Exporting Excel into
System.Data.DataSet
andSystem.Data.DataTable
objects allows easy interoperability or integration with DataGrids, SQL, and EF. - Memory stream
The inline code data types can be sent as a RESTful API response or used with IronPDF to convert them into a PDF document.
// Advanced example: converting an XLSX file to multiple formats using IronXL
using IronXL;
class AdvancedSpreadsheetConversion
{
static void Main()
{
// Load the Excel spreadsheet
WorkBook workbook = WorkBook.Load("advanced_sample.xlsx");
// Convert and save to various formats
workbook.SaveAs("advanced_sample.xlsm");
workbook.SaveAsCsv("advanced_sample.csv");
workbook.SaveAsJson("advanced_sample.json");
workbook.SaveAsXml("advanced_sample.xml");
workbook.ExportToHtml("advanced_sample.html");
// You can also convert to binary or byte array for advanced uses
byte[] excelAsByteArray = workbook.ToBinaryData();
}
}
// Advanced example: converting an XLSX file to multiple formats using IronXL
using IronXL;
class AdvancedSpreadsheetConversion
{
static void Main()
{
// Load the Excel spreadsheet
WorkBook workbook = WorkBook.Load("advanced_sample.xlsx");
// Convert and save to various formats
workbook.SaveAs("advanced_sample.xlsm");
workbook.SaveAsCsv("advanced_sample.csv");
workbook.SaveAsJson("advanced_sample.json");
workbook.SaveAsXml("advanced_sample.xml");
workbook.ExportToHtml("advanced_sample.html");
// You can also convert to binary or byte array for advanced uses
byte[] excelAsByteArray = workbook.ToBinaryData();
}
}
' Advanced example: converting an XLSX file to multiple formats using IronXL
Imports IronXL
Friend Class AdvancedSpreadsheetConversion
Shared Sub Main()
' Load the Excel spreadsheet
Dim workbook As WorkBook = WorkBook.Load("advanced_sample.xlsx")
' Convert and save to various formats
workbook.SaveAs("advanced_sample.xlsm")
workbook.SaveAsCsv("advanced_sample.csv")
workbook.SaveAsJson("advanced_sample.json")
workbook.SaveAsXml("advanced_sample.xml")
workbook.ExportToHtml("advanced_sample.html")
' You can also convert to binary or byte array for advanced uses
Dim excelAsByteArray() As Byte = workbook.ToBinaryData()
End Sub
End Class
The code above loads an ordinary XLSX file, then converts and exports it to several formats.
The Spreadsheet We Will Convert

The various files exported are shown below.





Frequently Asked Questions
What file formats can IronXL convert spreadsheets to?
IronXL can convert spreadsheets to various formats including XLS, XLSX, XLSM, XLTX, CSV, TSV, JSON, XML, and HTML.
How do you load a spreadsheet file using IronXL?
You can load a spreadsheet file using the `Load` method of the `WorkBook` class in IronXL.
Which method is used to export a spreadsheet to different file types?
The `SaveAs` method is used to export spreadsheets to various file types such as CSV, JSON, XML, and HTML. Dedicated methods like `SaveAsCsv`, `SaveAsJson`, `SaveAsXml`, and `ExportToHtml` are recommended for specific formats.
Can IronXL handle inline code data types?
Yes, IronXL can handle inline code data types including HTML string, Binary, Byte array, Data set, and Memory stream.
What is the purpose of the `WorkBook` class in IronXL?
The `WorkBook` class is used to load or create new XLS or XLSX files, view, add, or modify data, and export spreadsheets to various formats.
How can I check if the exported files are saved correctly?
After exporting, you can check the specified directory for the exported files to ensure they are saved correctly.
Is it possible to convert a spreadsheet to multiple formats at once using IronXL?
Yes, you can convert a spreadsheet to multiple formats at once by calling the respective methods for each format on the `WorkBook` object.
Can IronXL export to JSON or XML?
Yes, IronXL can export to JSON and XML using the `SaveAsJson` and `SaveAsXml` methods respectively.
What are the prerequisites for using IronXL in a project?
You need to install the IronXL C# library, which can be done through NuGet, to use it in your project for converting Excel files to other file formats.
What is the benefit of using IronXL for spreadsheet conversion?
IronXL provides a simple and efficient way to convert spreadsheets between various formats with support for inline data types and advanced options such as exporting to a memory stream or byte array for further processing.