Test in production without watermarks.
Works wherever you need it to.
Get 30 days of fully functional product.
Have it up and running in minutes.
Full access to our support engineering team during your product trial
In this tutorial, viewers learn how to export Excel spreadsheet data into various formats using C# and IronXL. The process begins with setting up a console application in Visual Studio 2022, followed by installing IronXL via the NuGet Package Manager. After importing the IronXL library in code, the Excel file is loaded using the Workbook.Load
function. The tutorial guides users through exporting the Excel file to different formats, including CSV, JSON, and XML, using the SaveAs
methods. For each file type, the path for the saved file is specified, and the generated files are reviewed to ensure data integrity and formatting consistency. The tutorial highlights IronXL’s effectiveness in maintaining original data formatting across exported files, making it a reliable tool for developers needing versatile data conversion capabilities. The tutorial concludes by offering support for further assistance, emphasizing IronXL's utility and user-friendliness in Excel data manipulation.
Here's a sample code snippet demonstrating how to achieve this:
// Ensure you have installed IronXL via the NuGet Package Manager in your Visual Studio project.
using System;
using IronXL;
class ExcelExportExample
{
static void Main()
{
// Load the Excel file using IronXL's Workbook.Load method.
// Replace "example.xlsx" with the path to your Excel file.
WorkBook workbook = WorkBook.Load("example.xlsx");
// Get the first worksheet in the Excel file.
WorkSheet sheet = workbook.WorkSheets.First();
// Export the Excel worksheet to CSV format.
// Provide the desired output path for the CSV file.
sheet.SaveAs("output.csv");
// Export the Excel worksheet to JSON format.
// Provide the desired output path for the JSON file.
sheet.SaveAsJson("output.json");
// Export the Excel worksheet to XML format.
// Provide the desired output path for the XML file.
sheet.SaveAsXml("output.xml");
Console.WriteLine("Excel data exported successfully to CSV, JSON, and XML formats.");
}
}
// Ensure you have installed IronXL via the NuGet Package Manager in your Visual Studio project.
using System;
using IronXL;
class ExcelExportExample
{
static void Main()
{
// Load the Excel file using IronXL's Workbook.Load method.
// Replace "example.xlsx" with the path to your Excel file.
WorkBook workbook = WorkBook.Load("example.xlsx");
// Get the first worksheet in the Excel file.
WorkSheet sheet = workbook.WorkSheets.First();
// Export the Excel worksheet to CSV format.
// Provide the desired output path for the CSV file.
sheet.SaveAs("output.csv");
// Export the Excel worksheet to JSON format.
// Provide the desired output path for the JSON file.
sheet.SaveAsJson("output.json");
// Export the Excel worksheet to XML format.
// Provide the desired output path for the XML file.
sheet.SaveAsXml("output.xml");
Console.WriteLine("Excel data exported successfully to CSV, JSON, and XML formats.");
}
}
' Ensure you have installed IronXL via the NuGet Package Manager in your Visual Studio project.
Imports System
Imports IronXL
Friend Class ExcelExportExample
Shared Sub Main()
' Load the Excel file using IronXL's Workbook.Load method.
' Replace "example.xlsx" with the path to your Excel file.
Dim workbook As WorkBook = WorkBook.Load("example.xlsx")
' Get the first worksheet in the Excel file.
Dim sheet As WorkSheet = workbook.WorkSheets.First()
' Export the Excel worksheet to CSV format.
' Provide the desired output path for the CSV file.
sheet.SaveAs("output.csv")
' Export the Excel worksheet to JSON format.
' Provide the desired output path for the JSON file.
sheet.SaveAsJson("output.json")
' Export the Excel worksheet to XML format.
' Provide the desired output path for the XML file.
sheet.SaveAsXml("output.xml")
Console.WriteLine("Excel data exported successfully to CSV, JSON, and XML formats.")
End Sub
End Class
Explanation:
WorkBook.Load
is used to load an existing Excel file.workbook.WorkSheets.First()
.SaveAs
, SaveAsJson
, and SaveAsXml
methods are employed to export data to CSV, JSON, and XML formats, respectively.For further assistance and advanced tutorials, please refer to the C# Export to Excel: Step by Step Tutorial.