How to Convert Spreadsheet File Types
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
: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 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 allow 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.
: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 it to several formats.
The Spreadsheet We Will Convert
The various files exported are shown below.