How to Convert Spreadsheet File Types in C# with IronXL
IronXL enables C# developers to convert spreadsheets between multiple formats including XLS, XLSX, CSV, JSON, XML, and HTML using simple Load and SaveAs methods, streamlining file format transformations in business applications.
IronXL supports the conversion of spreadsheet files between various formats, including XLS, XLSX, XLSM, XLTX, CSV, TSV, JSON, XML, and HTML. It also supports inline code data types such as HTML strings, binary data, byte arrays, DataSets, and MemoryStreams. 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.
This flexibility makes IronXL an essential tool for .NET developers working with Excel files in C# across different platforms and applications. Whether you're building data migration tools, reporting systems, or business intelligence applications, the ability to seamlessly convert between formats ensures compatibility with various systems and user requirements.
Quickstart: Convert an Excel Spreadsheet to JSONWith one simple line of code, IronXL lets you load an Excel file and export it as JSON - no complex configuration, just fast results. It's a perfect get-started example for developers needing swift file-type conversion.
-
1Install IronXL with NuGet Package Manager
-
2Copy and run this code snippet.
IronXL.WorkBook.Load("input.xlsx").SaveAsJson("output.json");C# -
3Deploy to test on your live environment
Start using IronXL in your project today with a free trial
Minimal Workflow (5 steps)

- Install the C# library for converting Excel files to other file formats
- Use the
WorkBookclass to load or create new XLS or XLSX - View, add, or modify data in the Excel spreadsheet using C#
- Utilize the methods in the
WorkBookclass to export the spreadsheet - Check the exported file in the specified directory
How Do I Convert Spreadsheet File Types?
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. This conversion process preserves data integrity while adapting to the structural requirements of each target format.
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- Optimized for comma-separated values with proper escapingSaveAsJson- Creates properly formatted JSON with data type preservationSaveAsXml- Generates well-formed XML with appropriate schemaExportToHtml- Produces styled HTML tables with formatting retained
fileName.sheetName.format. In the example below, the output for the CSV format would be sample.new_sheet.csv.using IronXL;
// 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 formatsImports IronXL
' 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 formatsEach export method is optimized for its target format. For instance, converting XLSX to CSV handles special characters and delimiters correctly, while JSON export maintains data types and hierarchical structures.
When Should I Use Each Format?
Understanding when to use each file format is crucial for business applications:
- CSV/TSV: Best for simple tabular data, database imports, or when you need maximum compatibility with other applications
- JSON: Ideal for web services, REST APIs, and modern JavaScript applications
- XML: Suitable for structured data exchange, configuration files, and legacy system integration
- HTML: Perfect for displaying data on websites or generating reports for email distribution
What Advanced Conversion Options Are Available?
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, including advanced scenarios like exporting to DataSet and DataTable for database operations.
Which File Formats Can I Load?
- XLS, XLSX, XLSM, and XLTX
- CSV (Comma-Separated Values)
- TSV (Tab-Separated Values)
Which Formats Can I Export To?
-
XLS, XLSX, and XLSM
-
CSV and TSV
-
JSON
-
XML
-
HTML
-
Inline code data types:
- HTML string
- Binary and byte arrays
DataSet: Exporting Excel intoSystem.Data.DataSetandSystem.Data.DataTableobjects allows easy interoperability or integration with DataGrids, SQL, and EF.MemoryStream
The inline code data types can be sent as a RESTful API response or used with IronPDF to convert them into a PDF document. This flexibility is particularly useful when creating spreadsheets dynamically in web applications.
using IronXL;
// 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.ToBinary();Imports IronXL
' 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.ToBinary()The code above loads an ordinary XLSX file, then converts and exports it to several formats. For comprehensive examples of file conversions, visit our conversion examples page.
What Does the Converted Output Look Like?

XLSX file
The various files exported are shown below.

TSV File Export

CSV File Export

JSON File Export

XML File Export

HTML File Export
Best Practices for File Conversion
When converting spreadsheet files, consider these best practices to ensure optimal results:
-
Preserve Data Integrity: Always verify that critical data, formulas, and formatting are maintained after conversion. Some formats like CSV don't support multiple sheets or formatting.
-
Handle Large Files Efficiently: For large spreadsheets, consider using streaming methods or processing data in chunks to manage memory usage effectively.
-
Error Handling: Implement proper error handling to catch conversion failures:
try { WorkBook workbook = WorkBook.Load("input.xlsx"); // Check if the file has data before converting if (workbook.WorkSheets.Count > 0 && workbook.DefaultWorkSheet.RowCount > 0) { workbook.SaveAsCsv("output.csv"); Console.WriteLine("Conversion successful!"); } else { Console.WriteLine("No data found in the spreadsheet."); } } catch (Exception ex) { Console.WriteLine($"Conversion failed: {ex.Message}"); }Imports System Try Dim workbook As WorkBook = WorkBook.Load("input.xlsx") ' Check if the file has data before converting If workbook.WorkSheets.Count > 0 AndAlso workbook.DefaultWorkSheet.RowCount > 0 Then workbook.SaveAsCsv("output.csv") Console.WriteLine("Conversion successful!") Else Console.WriteLine("No data found in the spreadsheet.") End If Catch ex As Exception Console.WriteLine($"Conversion failed: {ex.Message}") End Try -
Choose the Right Format: Select the output format based on your specific needs:
- Use
XLSXfor full Excel functionality - Choose
CSVfor simple data exchange - Select
JSONfor web applications and APIs - Pick
XMLfor structured data with schemas - Export to
HTMLfor web display
- Use
-
Character Encoding: Pay attention to character encoding, especially when dealing with international data. IronXL handles
UTF-8encoding by default, ensuring proper character representation across different systems.
For more detailed guidance on working with Excel files in .NET applications, explore the comprehensive IronXL documentation.
Frequently Asked Questions
What is IronXL used for in C# applications?
IronXL is used for converting Excel spreadsheets between various file formats like CSV, JSON, XML, and HTML in C# applications. It simplifies file format transformations using easy Load and SaveAs methods.
How can I convert an Excel file to JSON using IronXL?
You can convert an Excel file to JSON using IronXL with a simple line of code: `IronXL.WorkBook.Load("input.xlsx").SaveAsJson("output.json");`. This method loads the Excel file and exports it as a JSON file.
Which file formats does IronXL support for conversion?
IronXL supports conversion to and from multiple file formats, including XLS, XLSX, XLSM, XLTX, CSV, TSV, JSON, XML, and HTML. It can also interact with inline code data types and export to formats like DataSet and MemoryStream.
Can IronXL handle large spreadsheet files efficiently?
Yes, IronXL can handle large spreadsheet files efficiently by using streaming methods or processing data in chunks to manage memory usage, ensuring performance is maintained even when working with extensive data sets.
What is the recommended method for exporting an Excel file to CSV using IronXL?
For exporting an Excel file to CSV, it's recommended to use the `SaveAsCsv` method, which is optimized for handling CSV-specific requirements such as proper escaping of special characters and delimiters.
How does IronXL ensure data integrity during conversion?
IronXL preserves data integrity during conversion by maintaining the original data, types, and formatting across different file formats, ensuring that the transformed files remain consistent with the source Excel spreadsheets.
What are the best practices for converting files using IronXL?
Best practices for file conversion with IronXL include preserving data integrity, using appropriate error handling, choosing the suitable output format for your needs, and paying attention to character encoding.
When should I use JSON as the export format with IronXL?
JSON is an ideal export format when working with web services, REST APIs, and modern JavaScript applications due to its lightweight structure and ease of use in data interchange and integration.
Is it possible to convert Excel data into formats suitable for database operations with IronXL?
Yes, IronXL can export Excel data to formats suitable for database operations, such as `DataSet` and `DataTable`, allowing easy integration with SQL databases or other data processing systems.
What are the customization options available for converting spreadsheets using IronXL?
IronXL offers various customization options for converting spreadsheets, including specific export methods like SaveAsCsv or SaveAsJson for different formats, and the ability to convert Excel data into binary or byte arrays for advanced uses.

Curtis Chau holds a Bachelor’s degree in Computer Science (Carleton University) and specializes in front-end development with expertise in Node.js, TypeScript, JavaScript, and React. Passionate about crafting intuitive and aesthetically pleasing user interfaces, Curtis enjoys working with modern frameworks and creating well-structured, visually appealing manuals.