C Sharp Export to Excel

It is necessary to work with different formats of Excel spreadsheets and use C Sharp Export to Excel functionalities. Projects may need to use spreadsheet data in specific formats, including .xml, .csv, .xls, .xlsx , and .json. In this tutorial, we will learn how to export Excel spreadsheet data into different formats using C#.

Export to XLSX
using IronXL;
static void Main(string[] args)
{
    WorkBook wb = WorkBook.Load("XlsFile.xls");//Import .xls, .csv, or .tsv file
    wb.SaveAs("NewXlsxFile.xlsx");//Export as .xlsx file
}
Imports IronXL
Shared Sub Main(ByVal args() As String)
	Dim wb As WorkBook = WorkBook.Load("XlsFile.xls") 'Import .xls, .csv, or .tsv file
	wb.SaveAs("NewXlsxFile.xlsx") 'Export as .xlsx file
End Sub
Jump to Article
Export to XLS
using IronXL;
static void Main(string[] args)
{
    WorkBook wb = WorkBook.Load("XlsxFile.xlsx");//Import .xlsx, .csv or .tsv file
    wb.SaveAs("NewXlsFile.xls");//Export as .xls file
}
Imports IronXL
Shared Sub Main(ByVal args() As String)
	Dim wb As WorkBook = WorkBook.Load("XlsxFile.xlsx") 'Import .xlsx, .csv or .tsv file
	wb.SaveAs("NewXlsFile.xls") 'Export as .xls file
End Sub
Jump to Article
Export to CSV
using IronXL;
static void Main(string[] args)
{
    WorkBook wb = WorkBook.Load("sample.xlsx");  //Import .xlsx or xls file          
    wb.SaveAsCsv("NewCsvFile.csv"); //Export as .xls file
}
Imports IronXL
Shared Sub Main(ByVal args() As String)
	Dim wb As WorkBook = WorkBook.Load("sample.xlsx") 'Import .xlsx or xls file
	wb.SaveAsCsv("NewCsvFile.csv") 'Export as .xls file
End Sub
Jump to Article
Export to XML
using IronXL;
static void Main(string[] args)
{
    WorkBook wb = WorkBook.Load("sample.xlsx");  //Import .xlsx, .xls or .csv file          
    wb.SaveAsCsv("NewXmlFile.xml"); //Export as .xml file
}
Imports IronXL
Shared Sub Main(ByVal args() As String)
	Dim wb As WorkBook = WorkBook.Load("sample.xlsx") 'Import .xlsx, .xls or .csv file
	wb.SaveAsCsv("NewXmlFile.xml") 'Export as .xml file
End Sub
Jump to Article
Export to JSON
using IronXL;
static void Main(string[] args)
{
    WorkBook wb = WorkBook.Load("sample.xlsx"); //import Excel file
    wb.SaveAsJson("NewjsonFile.json"); //Export as JSON file
}
Imports IronXL
Shared Sub Main(ByVal args() As String)
	Dim wb As WorkBook = WorkBook.Load("sample.xlsx") 'import Excel file
	wb.SaveAsJson("NewjsonFile.json") 'Export as JSON file
End Sub
Jump to Article
Try IronXL free for development


Step 1

1. Get the IronXL Library

For an easy way to work with Excel files in .NET Core, try IronXL. Download IronXL DLL or install with NuGet for free use in development projects.

 PM > Install-Package IronXL.Excel

Download and add its reference in your project. IronXL classes can be accessed using IronXL namespace.


How to Tutorial

1. Export to Excel in C#

IronXL provides the most accessible way to export the data to Excel with ( .xls, .xlsx and .csv) files in .NET applications. It is also possible to export the data to .json and .xml files. Let's see one by one how easy it can be to export Excel file data into these formats.


2. C# Export to .XLSX File

It is very easy to export an Excel file with an .xlsx extension. Let's see the example. In the code below, our XlsFile.xls file exists in bin>Debug folder of the project.

Remember: Don't forget to write extension with file name while importing or exporting.

By default, new Excel files will be created in the bin>Debug folder of the project. If we want to create a new file in a custom path then we can use wb.SaveAs(@"E:\IronXL\NewXlsxFile.xlsx");. Read the tutorial here to learn more about how to export Excel files in .NET.

using IronXL;
static void Main(string[] args)
{
    WorkBook wb = WorkBook.Load("XlsFile.xls");//Import .xls, .csv, or .tsv file
    wb.SaveAs("NewXlsxFile.xlsx");//Export as .xlsx file
}
using IronXL;
static void Main(string[] args)
{
    WorkBook wb = WorkBook.Load("XlsFile.xls");//Import .xls, .csv, or .tsv file
    wb.SaveAs("NewXlsxFile.xlsx");//Export as .xlsx file
}
Imports IronXL
Shared Sub Main(ByVal args() As String)
	Dim wb As WorkBook = WorkBook.Load("XlsFile.xls") 'Import .xls, .csv, or .tsv file
	wb.SaveAs("NewXlsxFile.xlsx") 'Export as .xlsx file
End Sub
VB   C#


3. C# Export to .XLS File

It is also possible to export a file with the .xls extension using IronXL. For this purpose, lets see the example below.

using IronXL;
static void Main(string[] args)
{
    WorkBook wb = WorkBook.Load("XlsxFile.xlsx");//Import .xlsx, .csv or .tsv file
    wb.SaveAs("NewXlsFile.xls");//Export as .xls file
}
using IronXL;
static void Main(string[] args)
{
    WorkBook wb = WorkBook.Load("XlsxFile.xlsx");//Import .xlsx, .csv or .tsv file
    wb.SaveAs("NewXlsFile.xls");//Export as .xls file
}
Imports IronXL
Shared Sub Main(ByVal args() As String)
	Dim wb As WorkBook = WorkBook.Load("XlsxFile.xlsx") 'Import .xlsx, .csv or .tsv file
	wb.SaveAs("NewXlsFile.xls") 'Export as .xls file
End Sub
VB   C#


4. C# Export to .CSV File

We can easily export our .xlsx or .xls file into .csv using IronXL. Let's see one case that shows how to export Excel file to CSV (.csv) file.

using IronXL;
static void Main(string[] args)
{
    WorkBook wb = WorkBook.Load("sample.xlsx");  //Import .xlsx or xls file          
    wb.SaveAsCsv("NewCsvFile.csv"); //Export as .xls file
}
using IronXL;
static void Main(string[] args)
{
    WorkBook wb = WorkBook.Load("sample.xlsx");  //Import .xlsx or xls file          
    wb.SaveAsCsv("NewCsvFile.csv"); //Export as .xls file
}
Imports IronXL
Shared Sub Main(ByVal args() As String)
	Dim wb As WorkBook = WorkBook.Load("sample.xlsx") 'Import .xlsx or xls file
	wb.SaveAsCsv("NewCsvFile.csv") 'Export as .xls file
End Sub
VB   C#

The above code will create the following three CSV files:

It is very simple to understand why it created three .csv files. It is because sample.xlsx contains three Worksheets. Therefore, it will create three .csv files, and each Worksheet's Excel file data would export to the corresponding .csv file.

We can see the number of sheets in sample.xlsx here:

However, if there is one worksheet in the Excel file, then just one .csv file would be created.


5. C# Export to .XML File:

We can export our Excel file data into .XML file format. The below code will export sample.xlsx file data into a .xml file. It will create three XML files because sample.xlsx has three worksheets, same as in the earlier example.

using IronXL;
static void Main(string[] args)
{
    WorkBook wb = WorkBook.Load("sample.xlsx");  //Import .xlsx, .xls or .csv file          
    wb.SaveAsCsv("NewXmlFile.xml"); //Export as .xml file
}
using IronXL;
static void Main(string[] args)
{
    WorkBook wb = WorkBook.Load("sample.xlsx");  //Import .xlsx, .xls or .csv file          
    wb.SaveAsCsv("NewXmlFile.xml"); //Export as .xml file
}
Imports IronXL
Shared Sub Main(ByVal args() As String)
	Dim wb As WorkBook = WorkBook.Load("sample.xlsx") 'Import .xlsx, .xls or .csv file
	wb.SaveAsCsv("NewXmlFile.xml") 'Export as .xml file
End Sub
VB   C#


6. C# Export to .JSON File

Using IronXL makes it very easy to export Excel file data into JSON file format, as in the below code example. The code will export sample.xlsx file data into a .json file. It will again create three .json files due to the three Workheets of sample.xlsx.

using IronXL;
static void Main(string[] args)
{
    WorkBook wb = WorkBook.Load("sample.xlsx"); //import Excel file
    wb.SaveAsJson("NewjsonFile.json"); //Export as JSON file
}
using IronXL;
static void Main(string[] args)
{
    WorkBook wb = WorkBook.Load("sample.xlsx"); //import Excel file
    wb.SaveAsJson("NewjsonFile.json"); //Export as JSON file
}
Imports IronXL
Shared Sub Main(ByVal args() As String)
	Dim wb As WorkBook = WorkBook.Load("sample.xlsx") 'import Excel file
	wb.SaveAsJson("NewjsonFile.json") 'Export as JSON file
End Sub
VB   C#


Tutorial Quick Access

Object Reference

Read the IronXL Documentation including all namespaces, feature sets, methods fields, classes, and enums.

Read Object Reference