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.
Quickstart: Export Workbook to JSON in One Line
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.
Get started making PDFs with NuGet now:
Install IronXL with NuGet Package Manager
Copy and run this code snippet.
WorkBook workbook = WorkBook.Load("data.xlsx"); workbook.SaveAsJson("output.json");Deploy to test on your live environment
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 `.xlsx` extension
- 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.
Install-Package IronXL.Excel
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:
:path=/static-assets/excel/content-code-examples/how-to/c-sharp-export-to-excel-xlsx.cs
using IronXL;
// Import .xls, .csv, or .tsv file
WorkBook workbook = WorkBook.Load("XlsFile.xls");
// Export as .xlsx file
workbook.SaveAs("newFile.xlsx");using IronXL;
// Import .xls, .csv, or .tsv file
WorkBook workbook = WorkBook.Load("XlsFile.xls");
// Export as .xlsx file
workbook.SaveAs("newFile.xlsx");
using IronXL;
// Import .xls, .csv, or .tsv file
WorkBook workbook = WorkBook.Load("XlsFile.xls");
// Export as .xlsx file
workbook.SaveAs("newFile.xlsx");IRON VB CONVERTER ERROR developers@ironsoftware.comThe 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:
:path=/static-assets/excel/content-code-examples/how-to/c-sharp-export-to-excel-xlsx-stream.cs
using IronXL;
// Load the workbook
WorkBook workbook = WorkBook.Load("xlsFile.xlsx");
// Exports the workbook to a XLSX stream.
var stream = workbook.ToXlsxStream();
// Use the stream with other services
// Example: Upload to cloud storage, send via web API, etc.using IronXL;
// Load the workbook
WorkBook workbook = WorkBook.Load("xlsFile.xlsx");
// Exports the workbook to a XLSX stream.
var stream = workbook.ToXlsxStream();
using IronXL;
// Load the workbook
WorkBook workbook = WorkBook.Load("xlsFile.xlsx");
// Exports the workbook to a XLSX stream.
var stream = workbook.ToXlsxStream();
// Use the stream with other services
// Example: Upload to cloud storage, send via web API, etc.IRON VB CONVERTER ERROR developers@ironsoftware.comHow to Export Excel to XLS Format?
Legacy systems sometimes require the older .xls format. IronXL handles this conversion while maintaining backward compatibility:
:path=/static-assets/excel/content-code-examples/how-to/c-sharp-export-to-excel-xls.cs
using IronXL;
// Import .xlsx, .csv or .tsv file
WorkBook workbook = WorkBook.Load("XlsxFile.xlsx");
// Export as .xls file
workbook.SaveAs("newFile.xls");using IronXL;
// Import .xlsx, .csv or .tsv file
WorkBook workbook = WorkBook.Load("XlsxFile.xlsx");
// Export as .xls file
workbook.SaveAs("newFile.xls");
using IronXL;
// Import .xlsx, .csv or .tsv file
WorkBook workbook = WorkBook.Load("XlsxFile.xlsx");
// Export as .xls file
workbook.SaveAs("newFile.xls");IRON VB CONVERTER ERROR developers@ironsoftware.comThis 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:
:path=/static-assets/excel/content-code-examples/how-to/c-sharp-export-to-excel-xls-stream.cs
using IronXL;
// Load the workbook
WorkBook workbook = WorkBook.Load("xlsxFile.xlsx");
// Exports the workbook to a XLS stream.
var stream = workbook.ToXlsStream();
// Stream can be used for legacy system integration
// Example: Send to legacy API endpoints, store in binary databasesusing IronXL;
// Load the workbook
WorkBook workbook = WorkBook.Load("xlsxFile.xlsx");
// Exports the workbook to a XLS stream.
var stream = workbook.ToXlsStream();
using IronXL;
// Load the workbook
WorkBook workbook = WorkBook.Load("xlsxFile.xlsx");
// Exports the workbook to a XLS stream.
var stream = workbook.ToXlsStream();
// Stream can be used for legacy system integration
// Example: Send to legacy API endpoints, store in binary databasesIRON VB CONVERTER ERROR developers@ironsoftware.comHow 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:
:path=/static-assets/excel/content-code-examples/how-to/c-sharp-export-to-excel-csv.cs
using IronXL;
// Import .xlsx or xls file
WorkBook workbook = WorkBook.Load("sample.xlsx");
// Export as .csv file
workbook.SaveAsCsv("newFile.csv");using IronXL;
// Import .xlsx or xls file
WorkBook workbook = WorkBook.Load("sample.xlsx");
// Export as .xls file
workbook.SaveAsCsv("newFile.csv");
using IronXL;
// Import .xlsx or xls file
WorkBook workbook = WorkBook.Load("sample.xlsx");
// Export as .csv file
workbook.SaveAsCsv("newFile.csv");IRON VB CONVERTER ERROR developers@ironsoftware.comWhen 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:
:path=/static-assets/excel/content-code-examples/how-to/c-sharp-export-to-excel-csv-stream.cs
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);
// Process the stream (e.g., upload to API, save to database)
// The stream contains only data from the first worksheetusing 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);
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);
// Process the stream (e.g., upload to API, save to database)
// The stream contains only data from the first worksheetIRON VB CONVERTER ERROR developers@ironsoftware.comHow 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:
:path=/static-assets/excel/content-code-examples/how-to/c-sharp-export-to-excel-csv-streams.cs
using IronXL;
// Load the workbook
WorkBook workbook = WorkBook.Load("sample.xlsx");
// Exports the entire workbook to CSV streams
var workBookStream = workbook.ToCsvStreams();
// Each stream in the collection represents a worksheet
// Process streams individually for batch operationsusing IronXL;
// Load the workbook
WorkBook workbook = WorkBook.Load("sample.xlsx");
// Exports the entire workbook to a CSV stream
var workBookStream = workbook.ToCsvStreams();
using IronXL;
// Load the workbook
WorkBook workbook = WorkBook.Load("sample.xlsx");
// Exports the entire workbook to CSV streams
var workBookStream = workbook.ToCsvStreams();
// Each stream in the collection represents a worksheet
// Process streams individually for batch operationsIRON VB CONVERTER ERROR developers@ironsoftware.comHow 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:
:path=/static-assets/excel/content-code-examples/how-to/c-sharp-export-to-excel-xml.cs
using IronXL;
// Import .xlsx, .xls or .csv file
WorkBook workbook = WorkBook.Load("sample.xlsx");
// Export as .xml file
workbook.SaveAsXml("newFile.xml");using IronXL;
// Import .xlsx, .xls or .csv file
WorkBook workbook = WorkBook.Load("sample.xlsx");
// Export as .xml file
workbook.SaveAsXml("newFile.xml");
using IronXL;
// Import .xlsx, .xls or .csv file
WorkBook workbook = WorkBook.Load("sample.xlsx");
// Export as .xml file
workbook.SaveAsXml("newFile.xml");IRON VB CONVERTER ERROR developers@ironsoftware.comThe 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:
:path=/static-assets/excel/content-code-examples/how-to/c-sharp-export-to-excel-xml-stream.cs
using IronXL;
// Load the workbook
WorkBook workbook = WorkBook.Load("sample.xlsx");
// Converts the first worksheet to a XML Stream
var stream = workbook.ToXmlStream(0);
// Stream can be processed without file I/O operations
// Ideal for web services and API integrationsusing IronXL;
// Load the workbook
WorkBook workbook = WorkBook.Load("sample.xlsx");
// Converts the first worksheet to a XML Stream
var stream = workbook.ToXmlStream(0);
using IronXL;
// Load the workbook
WorkBook workbook = WorkBook.Load("sample.xlsx");
// Converts the first worksheet to a XML Stream
var stream = workbook.ToXmlStream(0);
// Stream can be processed without file I/O operations
// Ideal for web services and API integrationsIRON VB CONVERTER ERROR developers@ironsoftware.comHow 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:
:path=/static-assets/excel/content-code-examples/how-to/c-sharp-export-to-excel-xml-streams.cs
using IronXL;
// Load the workbook
WorkBook workbook = WorkBook.Load("sample.xlsx");
// Exports the entire workbook to XML streams
var workBookStream = workbook.ToXmlStreams();
// Each stream represents a worksheet in XML format
// Perfect for batch processing and parallel operationsusing IronXL;
// Load the workbook
WorkBook workbook = WorkBook.Load("sample.xlsx");
// Exports the entire workbook to a XML stream
var workBookStream = workbook.ToXmlStreams();
using IronXL;
// Load the workbook
WorkBook workbook = WorkBook.Load("sample.xlsx");
// Exports the entire workbook to XML streams
var workBookStream = workbook.ToXmlStreams();
// Each stream represents a worksheet in XML format
// Perfect for batch processing and parallel operationsIRON VB CONVERTER ERROR developers@ironsoftware.comHow 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:
:path=/static-assets/excel/content-code-examples/how-to/c-sharp-export-to-excel-json.cs
using IronXL;
// Import Excel file
WorkBook workbook = WorkBook.Load("sample.xlsx");
// Export as JSON file
workbook.SaveAsJson("newFile.json");using IronXL;
// Import Excel file
WorkBook workbook = WorkBook.Load("sample.xlsx");
// Export as JSON file
workbook.SaveAsJson("newFile.json");
using IronXL;
// Import Excel file
WorkBook workbook = WorkBook.Load("sample.xlsx");
// Export as JSON file
workbook.SaveAsJson("newFile.json");IRON VB CONVERTER ERROR developers@ironsoftware.comThe 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:
:path=/static-assets/excel/content-code-examples/how-to/c-sharp-export-to-excel-json-stream.cs
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);
// Stream can be returned directly in web API responses
// No temporary files needed for JSON conversionusing 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);
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);
// Stream can be returned directly in web API responses
// No temporary files needed for JSON conversionIRON VB CONVERTER ERROR developers@ironsoftware.comWhen 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:
:path=/static-assets/excel/content-code-examples/how-to/c-sharp-export-to-excel-json-streams.cs
using IronXL;
// Load the workbook
WorkBook workbook = WorkBook.Load("sample.xlsx");
// Exports the entire workbook to JSON streams
var workBookStream = workbook.ToJsonStreams();
// Each stream contains JSON data for one worksheet
// Maintains workbook structure in JSON formatusing IronXL;
// Load the workbook
WorkBook workbook = WorkBook.Load("sample.xlsx");
// Exports the entire workbook to a JSON stream
var workBookStream = workbook.ToJsonStreams();
using IronXL;
// Load the workbook
WorkBook workbook = WorkBook.Load("sample.xlsx");
// Exports the entire workbook to JSON streams
var workBookStream = workbook.ToJsonStreams();
// Each stream contains JSON data for one worksheet
// Maintains workbook structure in JSON formatIRON VB CONVERTER ERROR developers@ironsoftware.comWhat 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
How can I export Excel files to different formats in C# without Microsoft Office?
IronXL allows you to export Excel files to multiple formats including XLSX, XLS, CSV, XML, and JSON without requiring Microsoft Office dependencies. The library provides simple one-line methods for each export format, making it easy to convert between different file types programmatically.
What is the simplest way to convert an Excel file to JSON in C#?
With IronXL, you can convert an Excel file to JSON in just two lines of code: WorkBook workbook = WorkBook.Load("data.xlsx"); workbook.SaveAsJson("output.json");. This straightforward approach eliminates the need for complex parsing or manual data extraction.
Which file formats can I export Excel data to using C#?
IronXL supports exporting Excel workbooks to various formats including: Excel formats (.xlsx and .xls), data interchange formats (.csv, .json, and .xml), and tab-separated values (.tsv). Each format is optimized for specific use cases like database imports, web APIs, or enterprise system integration.
How do I install the Excel export library for my C# project?
You can install IronXL through NuGet Package Manager or by downloading the DLL directly. The library supports .NET Framework, .NET Core, and .NET 5+ applications, making it compatible with modern development environments including Azure and Docker deployments.
Can I convert legacy XLS files to modern XLSX format in C#?
Yes, IronXL makes it simple to convert between Excel formats. You can load an older .xls file using WorkBook.Load() and save it as a modern .xlsx file, preserving all data integrity throughout the conversion process.
What methods does the library provide for exporting Excel data?
IronXL provides dedicated methods for each export format: SaveAsCsv() for CSV files, SaveAsJson() for JSON output, SaveAsXml() for XML format, and standard Save() with appropriate extensions for Excel formats. These methods handle all file type conversions internally.







