How to Convert Spreadsheet File Types
Introduction
IronXL supports converting spreadsheet file from file formats: XLS, XLSX, XLSM, XLTX, CSV, TSV to file formats: XLS, XLSX, XLSM, CSV, TSV, JSON, XML or HTML including inline code data types: HTML string, Binary, Byte array, Data set, and Memory stream. The Load method is used to open spreadsheet file and the SaveAs
method is used to export spreadsheet to desired file type.
How to Convert and Export (XLSX, XLS, XLSM, XLTX, CSV) in C#

- Install C# library to convert Excel file to other file formats
- Use
WorkBook
class to load or create new XLS or XLSX - View, add or modify data in Excel spreadsheet in C#
- Utilize methods in
WorkBook
class to export the spreadsheet - Check the exported file in specified directory

Install with NuGet
Install-Package IronXL.Excel
How to Convert Spreadsheet Type
The idea of converting spreadsheet type is to load the file from one of the supported type and export it to another format. Hence, the converting process happens within IronXL ingenious restructuring of data.
Although SaveAs
can be used to export CSV, JSON, XML and HTML. Exclusive methods for each of these file format is recommended:
SaveAsCsv
SaveAsJson
SaveAsXml
ExportToHtml
Please note
- For CSV, TSV, JSON, and XML file format, each file will be created corresponding to each worksheet. The naming convention would be fileName.sheetName.format. In the example below the output for CSV format would be sample.new_sheet.csv.
:path=/static-assets/excel/content-code-examples/how-to/convert-spreadsheet-file-types-convert.cs
using IronXL;
// Import any XLSX, XLS, XLSM, XLTX, CSV and TSV
WorkBook workBook = WorkBook.Load("sample.xlsx");
// Export the excel file as XLS, XLSX, XLSM, CSV, TSV, JSON, XML
workBook.SaveAs("sample.xls");
workBook.SaveAs("sample.tsv");
workBook.SaveAsCsv("sample.csv");
workBook.SaveAsJson("sample.json");
workBook.SaveAsXml("sample.xml");
// Export the excel file as Html
workBook.ExportToHtml("sample.html");
Imports IronXL
' Import any XLSX, XLS, XLSM, XLTX, CSV and TSV
Private workBook As WorkBook = WorkBook.Load("sample.xlsx")
' Export the excel file as XLS, XLSX, XLSM, CSV, TSV, JSON, XML
workBook.SaveAs("sample.xls")
workBook.SaveAs("sample.tsv")
workBook.SaveAsCsv("sample.csv")
workBook.SaveAsJson("sample.json")
workBook.SaveAsXml("sample.xml")
' Export the excel file as Html
workBook.ExportToHtml("sample.html")
Advanced
In the last section we only explore the most common file formats. However, IronXL can convert spreadsheet to many more formats. Explore all possible options for loading and exporting spreadsheet.
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 allow easy interoperability or integration with DataGrids, SQL and EF. - Memory stream
The inline code data types is can be sent as a restful API respond or be used with IronPDF to convert into PDF document.
:path=/static-assets/excel/content-code-examples/how-to/convert-spreadsheet-file-types-convert-advance.cs
using IronXL;
using System.IO;
// Import any XLSX, XLS, XLSM, XLTX, CSV and TSV
WorkBook workBook = WorkBook.Load("sample.xlsx");
// Export the excel file as XLS, XLSX, XLSM, CSV, TSV, JSON, XML
workBook.SaveAs("sample.xls");
workBook.SaveAs("sample.xlsx");
workBook.SaveAs("sample.tsv");
workBook.SaveAsCsv("sample.csv");
workBook.SaveAsJson("sample.json");
workBook.SaveAsXml("sample.xml");
// Export the excel file as Html, Html string
workBook.ExportToHtml("sample.html");
string htmlString = workBook.ExportToHtmlString();
// Export the excel file as Binary, Byte array, Data set, Stream
byte[] binary = workBook.ToBinary();
byte[] byteArray = workBook.ToByteArray();
System.Data.DataSet dataSet = workBook.ToDataSet(); // Allow easy integration with DataGrids, SQL and EF
Stream stream = workBook.ToStream();
Imports IronXL
Imports System.IO
' Import any XLSX, XLS, XLSM, XLTX, CSV and TSV
Private workBook As WorkBook = WorkBook.Load("sample.xlsx")
' Export the excel file as XLS, XLSX, XLSM, CSV, TSV, JSON, XML
workBook.SaveAs("sample.xls")
workBook.SaveAs("sample.xlsx")
workBook.SaveAs("sample.tsv")
workBook.SaveAsCsv("sample.csv")
workBook.SaveAsJson("sample.json")
workBook.SaveAsXml("sample.xml")
' Export the excel file as Html, Html string
workBook.ExportToHtml("sample.html")
Dim htmlString As String = workBook.ExportToHtmlString()
' Export the excel file as Binary, Byte array, Data set, Stream
Dim binary() As Byte = workBook.ToBinary()
Dim byteArray() As Byte = workBook.ToByteArray()
Dim dataSet As System.Data.DataSet = workBook.ToDataSet() ' Allow easy integration with DataGrids, SQL and EF
Dim stream As Stream = workBook.ToStream()
The code above Loads an ordinary XLSX file then converts and exports to several formats.
The Spreadsheet We Will Convert

The various files exported are shown below.




