C# Export to Excel: Complete Developer Guide
Export Excel files to multiple formats in C# using IronXL, including .xlsx, .xls, .csv, .xml, and .json without Microsoft Office dependencies. The library provides one-line methods for each export format.
Load your existing Excel file and export it to JSON in just one line with IronXL's API. Start exporting Excel files without writing boilerplate code.
-
1Install IronXL with NuGet Package Manager
-
2Copy and run this code snippet.
WorkBook workbook = WorkBook.Load("data.xlsx"); workbook.SaveAsJson("output.json");C# -
3Deploy to test on your live environment
Start using IronXL in your project today with a free trial
Minimal Workflow (6 steps)
- Download the C# library to export Excel files
- Load existing Excel workbooks using the
WorkBook.Load()method - Export to XLSX format with the
.xlsxextension - Convert Excel files to CSV using
SaveAsCsv() - Export spreadsheet data to XML with
SaveAsXml() - Generate JSON files from Excel using
SaveAsJson()
Step 1
How to Install IronXL for Excel Export?
IronXL provides a direct approach to working with Excel files in .NET applications. Download the IronXL DLL directly or install via NuGet for development and testing.
After installation, add the IronXL reference to access all Excel manipulation features through the IronXL namespace. The library supports .NET Framework, .NET Core, and .NET 5+ applications, making it compatible with modern development environments. For specific deployment scenarios, refer to guides on deploying to Azure or setting up in Docker.
How to Tutorial
What Excel Export Formats Does C# Support?
IronXL enables data export from Excel workbooks to multiple file formats. The library supports exporting to:
- Excel formats:
.xlsx(modern) and.xls(legacy) - Data interchange formats:
.csv,.json, and.xml - Tab-separated values:
.tsv
Each format serves specific use cases - CSV for database imports, JSON for web APIs, and XML for enterprise system integration. Export these formats to their respective output streams to integrate with other applications. The library handles all spreadsheet file type conversions internally, preserving data integrity throughout the process.
How to Export Excel to XLSX in C#?
Converting between Excel formats is straightforward with IronXL. The following example demonstrates loading an older .xls file and saving it as a modern .xlsx file:
using IronXL;
// Import .xls, .csv, or .tsv file
WorkBook workbook = WorkBook.Load("XlsFile.xls");
// Export as .xlsx file
workbook.SaveAs("newFile.xlsx");Imports IronXL
' Import .xls, .csv, or .tsv file
Private workbook As WorkBook = WorkBook.Load("XlsFile.xls")
' Export as .xlsx file
workbook.SaveAs("newFile.xlsx")The SaveAs method automatically detects the desired format based on the file extension. When converting from .xls to .xlsx, the process preserves all worksheets, formulas, formatting, and data types. This conversion is particularly useful when modernizing legacy Excel files for compatibility with newer Office versions.
How to Export Excel to XLSX Stream?
Use ToXlsxStream to export the document to an XLSX stream for integration with other applications. This approach is essential when working with cloud storage services or when processing Excel data in memory without creating temporary files:
using IronXL;
// Load the workbook
WorkBook workbook = WorkBook.Load("xlsFile.xlsx");
// Exports the workbook to a XLSX stream.
var stream = workbook.ToXlsxStream();Imports IronXL
' Load the workbook
Private workbook As WorkBook = WorkBook.Load("xlsFile.xlsx")
' Exports the workbook to a XLSX stream.
Private stream = workbook.ToXlsxStream()How to Export Excel to XLS Format?
Legacy systems sometimes require the older .xls format. IronXL handles this conversion while maintaining backward compatibility:
using IronXL;
// Import .xlsx, .csv or .tsv file
WorkBook workbook = WorkBook.Load("XlsxFile.xlsx");
// Export as .xls file
workbook.SaveAs("newFile.xls");Imports IronXL
' Import .xlsx, .csv or .tsv file
Private workbook As WorkBook = WorkBook.Load("XlsxFile.xlsx")
' Export as .xls file
workbook.SaveAs("newFile.xls")This conversion maintains compatibility with Excel 97-2003 versions. The SaveAs method handles the format conversion internally, ensuring data integrity while adapting to the .xls format limitations such as the 65,536 row limit per worksheet. For applications that need to manage worksheets with larger datasets, consider staying with the modern .xlsx format.
When Should I Export to XLS Stream?
IronXL also supports exporting as an XLS stream. This is particularly useful when integrating with legacy enterprise systems that require XLS format but operate through APIs rather than file systems:
using IronXL;
// Load the workbook
WorkBook workbook = WorkBook.Load("xlsxFile.xlsx");
// Exports the workbook to a XLS stream.
var stream = workbook.ToXlsStream();Imports IronXL
' Load the workbook
Dim workbook As WorkBook = WorkBook.Load("xlsxFile.xlsx")
' Exports the workbook to a XLS stream.
Dim stream = workbook.ToXlsStream()How to Convert Excel to CSV in C#?
CSV export is essential for data exchange between different systems. IronXL provides a dedicated method for CSV conversion that handles multi-sheet workbooks intelligently:
using IronXL;
// Import .xlsx or xls file
WorkBook workbook = WorkBook.Load("sample.xlsx");
// Export as .csv file
workbook.SaveAsCsv("newFile.csv");
When exporting multi-sheet workbooks, IronXL creates separate CSV files for each worksheet. For a workbook with three sheets named "Sheet1", "Sheet2", and "Sheet3", the export generates:
Multiple CSV files generated from a three-sheet Excel workbook, with each worksheet exported as a separate CSV file
The SaveAsCsv method preserves data values while removing formatting, formulas, and other Excel-specific features. This makes CSV ideal for importing data into databases or processing with other applications. For more complex data manipulation before export, explore the guide on converting DataTable to CSV.
How to Export Single Worksheet to CSV Stream?
To convert only a specified worksheet within the workbook to a CSV stream, use the ToCsvStream method with an integer indicating the worksheet's index. This approach is useful when processing specific sheets independently:
using IronXL;
// Load the workbook
WorkBook workbook = WorkBook.Load("sample.xlsx");
// Exports the first sheet of the workbook to a CSV stream
var stream = workbook.ToCsvStream(0);Imports IronXL
' Load the workbook
Private workbook As WorkBook = WorkBook.Load("sample.xlsx")
' Exports the first sheet of the workbook to a CSV stream
Private stream = workbook.ToCsvStream(0)How to Export All Worksheets to CSV Streams?
IronXL supports converting the entire workbook into CSV streams using the ToCsvStreams method. This returns a collection of streams, one for each worksheet:
using IronXL;
// Load the workbook
WorkBook workbook = WorkBook.Load("sample.xlsx");
// Exports the entire workbook to a CSV stream
var workBookStream = workbook.ToCsvStreams();Imports IronXL
' Load the workbook
Private workbook As WorkBook = WorkBook.Load("sample.xlsx")
' Exports the entire workbook to a CSV stream
Private workBookStream = workbook.ToCsvStreams()How to Export Excel Data to XML?
XML export enables structured data exchange with enterprise systems. IronXL simplifies this process while maintaining the hierarchical structure of your spreadsheet data:
using IronXL;
// Import .xlsx, .xls or .csv file
WorkBook workbook = WorkBook.Load("sample.xlsx");
// Export as .xml file
workbook.SaveAsXml("newFile.xml");Imports IronXL
' Import .xlsx, .xls or .csv file
Private workbook As WorkBook = WorkBook.Load("sample.xlsx")
' Export as .xml file
workbook.SaveAsXml("newFile.xml")The SaveAsXml method converts each worksheet into a separate XML file with a structured representation of the spreadsheet data. This includes:
- Cell values and data types
- Row and column positioning
- Basic structural information
XML export is particularly valuable for integrating Excel data with web services or systems that require structured data formats. For more advanced Excel conversion scenarios, see the comprehensive guide on converting XLSX to various formats.
When Should I Use XML Stream Export?
To export a specified worksheet to an XML stream, use the ToXmlStream method with an integer parameter representing the worksheet index. This is ideal for real-time data processing scenarios:
using IronXL;
// Load the workbook
WorkBook workbook = WorkBook.Load("sample.xlsx");
// Converts the first worksheet to a XML Stream
var stream = workbook.ToXmlStream(0);Imports IronXL
' Load the workbook
Private workbook As WorkBook = WorkBook.Load("sample.xlsx")
' Converts the first worksheet to a XML Stream
Private stream = workbook.ToXmlStream(0)How to Export Multiple Worksheets to XML Streams?
To export the entire workbook as XML streams, use the ToXmlStreams method. This approach maintains separation between worksheets while providing programmatic access to each:
using IronXL;
// Load the workbook
WorkBook workbook = WorkBook.Load("sample.xlsx");
// Exports the entire workbook to a XML stream
var workBookStream = workbook.ToXmlStreams();Imports IronXL
' Load the workbook
Private workbook As WorkBook = WorkBook.Load("sample.xlsx")
' Exports the entire workbook to a XML stream
Private workBookStream = workbook.ToXmlStreams()How to Generate JSON from Excel Files?
Modern web applications often require JSON format for data exchange. IronXL provides direct JSON export functionality that converts Excel data into web-friendly JSON structures:
using IronXL;
// Import Excel file
WorkBook workbook = WorkBook.Load("sample.xlsx");
// Export as JSON file
workbook.SaveAsJson("newFile.json");Imports IronXL
' Import Excel file
Private workbook As WorkBook = WorkBook.Load("sample.xlsx")
' Export as JSON file
workbook.SaveAsJson("newFile.json")The SaveAsJson method creates JSON files with array-based structures representing spreadsheet data. Each worksheet exports as a separate JSON file, making it easy to:
- Integrate with RESTful APIs
- Process data in JavaScript applications
- Store spreadsheet data in NoSQL databases
For advanced scenarios, combine JSON export with IronXL's data manipulation features to transform data before exporting. This is particularly useful when working with ASP.NET web applications that need to serve Excel data via web APIs.
How to Export Single Worksheet as JSON Stream?
To convert a specified worksheet to a JSON stream, use the ToJsonStream method with an integer as the worksheet index. This enables direct API response streaming without intermediate files:
using IronXL;
// Load the workbook
WorkBook workbook = WorkBook.Load("sample.xlsx");
// Exports the first sheet of the workbook to a JSON stream
var stream = workbook.ToJsonStream(0);Imports IronXL
' Load the workbook
Private workbook As WorkBook = WorkBook.Load("sample.xlsx")
' Exports the first sheet of the workbook to a JSON stream
Private stream = workbook.ToJsonStream(0)When to Export Entire Workbook as JSON Streams?
To convert the entire workbook to JSON streams, use the ToJsonStreams method. This approach is beneficial when maintaining the worksheet structure in your JSON output:
using IronXL;
// Load the workbook
WorkBook workbook = WorkBook.Load("sample.xlsx");
// Exports the entire workbook to a JSON stream
var workBookStream = workbook.ToJsonStreams();Imports IronXL
' Load the workbook
Private workbook As WorkBook = WorkBook.Load("sample.xlsx")
' Exports the entire workbook to a JSON stream
Private workBookStream = workbook.ToJsonStreams()What Resources Help With Excel Export Development?
API Reference Documentation
Explore the complete IronXL API including all namespaces, classes, methods, and properties for advanced Excel manipulation.
View API ReferenceReady to Export Excel Files?
IronXL simplifies Excel file export operations in C# applications. Whether converting between Excel formats or exporting to data interchange formats like CSV, JSON, or XML, the library provides intuitive methods that handle complex conversions automatically.
Start implementing Excel export functionality today with a free trial of IronXL. For production deployments, explore flexible licensing options designed for teams of all sizes.
Frequently Asked Questions
What are the key features of IronXL for exporting Excel files?
IronXL provides one-line methods for exporting Excel files to various formats including XLSX, CSV, JSON, XML, and more, without Microsoft Office dependencies.
How can I start exporting Excel files in C#?
Begin by installing IronXL via NuGet or by downloading the DLL. Then, use its straightforward API to load and export Excel files in various formats.
Is it possible to export Excel files to JSON using IronXL?
Yes, IronXL allows you to export Excel workbooks to JSON using the `SaveAsJson` method, which is useful for web applications needing JSON structures.
Can IronXL export Excel data without intermediate files?
Yes, with IronXL's stream methods such as `ToXlsxStream`, `ToJsonStream`, and others, you can export Excel data directly to streams without creating intermediate files.
Which file formats does IronXL support for exporting Excel data?
IronXL supports exporting Excel data to XLSX, XLS, CSV, JSON, XML, and TSV formats.
How does IronXL handle multi-sheet Excel workbooks during CSV export?
IronXL exports each worksheet of a multi-sheet workbook as a separate CSV file, intelligently managing workbook contents.
Can IronXL be used for legacy file handling?
Yes, IronXL can export Excel files to the legacy .xls format, ensuring compatibility with older systems and Excel versions.
Does IronXL support exporting Excel data to XML?
IronXL makes it easy to export Excel data to XML files, which is ideal for structured data exchange with enterprise systems.
How do I export a single worksheet to a JSON stream in IronXL?
Use the `ToJsonStream` method and specify the worksheet index to export only that particular worksheet as a JSON stream.
What development environments are compatible with IronXL?
IronXL supports .NET Framework, .NET Core, and .NET 5+, making it compatible with modern development environments.

Jacob Mellor is Chief Technology Officer at Iron Software and a visionary engineer pioneering C# PDF technology. As the original developer behind Iron Software's core codebase, he has shaped the company's product architecture since its inception, transforming it alongside CEO Cameron Rimington into a 50+ person company serving NASA, Tesla, and global government agencies.
