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 the digital world, data sharing across platforms is crucial, with Excel being a popular format. However, there are instances where data needs to be shared in other formats like PDF or CSV. This article explores how to programmatically export data from Excel using ASP.NET Core.
IronXL is a powerful ASP.NET Entity Framework Core library that provides developers with a new user convenient and efficient way to work with Excel files in ASP.NET Core applications. With IronXL, developers can read, write, and manipulate Excel files, perform data analysis and processing, and generate reports with ease. ASP.NET Core is a widely used Web Application framework that allows developers to create dynamic Web Applications using a variety of programming languages, including C#. One of the key components of many Web Applications is the ability to read and write data to and from Excel files.
Once you have installed Visual Studio, ASP.NET, and IronXL, you can create a new ASP.NET project in Visual Studio and begin writing code to export Excel to different formats using IronXL.
To make use of the IronXL library, you must create a .NET project in Visual Studio. While any version of Visual Studio can be used, it is recommended to use the latest version. You can choose from various project templates, such as Windows Forms, depending on your requirements. To simplify the process, this tutorial will be using the Console Application.
New project window
After selecting the project type, provide a name for the project and designate its location. Then, choose the desired framework for the project, such as .NET Core 6.
Project configuration
Once the solution is created, the Program.cs
file will be opened, enabling you to enter code and construct/run the application.
New project
Finally, you can incorporate the library to test the code.
The IronXL Library can be downloaded and installed in many different ways.
These are:
To install the IronXL library, the NuGet Package Manager can be used. Open the NuGet Package Manager and search for IronXL in the browse tab. Choose IronXL from the search results and install it. Once the installation is complete, this project will be set up to use the IronXL library.
The screenshot below shows how to open the NuGet Package Manager in Visual Studio:
NuGet Package Manager
IronXL in search results:
Search result
Using a console to perform operations is a popular choice for many. If you prefer to install IronXL through the command line, you can follow these steps:
Install-Package IronXL.Excel
Now the package will download and install to the current project and be ready to use.
Installing project dependencies
Using IronXL, you can export a database table of an Excel file to CSV files, XML files, and even JSON files. You can also read data from real Excel files and export them to other formats, such as Excel. Using the IronXL controller, you can convert and stream worksheets, model classes, models, and card footers, and even embed colors from Excel exports to different formats.
Converting Excel files to CSV format is a common requirement for data processing and exchange. Converting CSV files manually can be quite bothersome. Here, this tutorial will use IronXL to convert an Excel file to a CSV file. The source code below shows how you can easily convert an XLSX file to a CSV file in just a few lines of code.
using IronXL; // Using IronXL library for Excel operations
using System;
using System.Linq;
// Load the Excel workbook
WorkBook workBook = WorkBook.Load("multiple.xlsx");
// Save the workbook's data as a CSV file
workBook.SaveAsCsv("sample.csv");
using IronXL; // Using IronXL library for Excel operations
using System;
using System.Linq;
// Load the Excel workbook
WorkBook workBook = WorkBook.Load("multiple.xlsx");
// Save the workbook's data as a CSV file
workBook.SaveAsCsv("sample.csv");
Imports IronXL ' Using IronXL library for Excel operations
Imports System
Imports System.Linq
' Load the Excel workbook
Private workBook As WorkBook = WorkBook.Load("multiple.xlsx")
' Save the workbook's data as a CSV file
workBook.SaveAsCsv("sample.csv")
CSV file
Converting Excel files to XML format can be useful for exchanging data between different systems, services, or applications.
Similarly to converting to CSV, you can easily convert an Excel file to XML using IronXL in just a few lines of code.
using IronXL; // Using IronXL library for Excel operations
using System;
using System.Linq;
// Load the Excel workbook
WorkBook workBook = WorkBook.Load("multiple.xlsx");
// Save the workbook's data as an XML file
workBook.SaveAsXml("sample.xml");
using IronXL; // Using IronXL library for Excel operations
using System;
using System.Linq;
// Load the Excel workbook
WorkBook workBook = WorkBook.Load("multiple.xlsx");
// Save the workbook's data as an XML file
workBook.SaveAsXml("sample.xml");
Imports IronXL ' Using IronXL library for Excel operations
Imports System
Imports System.Linq
' Load the Excel workbook
Private workBook As WorkBook = WorkBook.Load("multiple.xlsx")
' Save the workbook's data as an XML file
workBook.SaveAsXml("sample.xml")
File output
Converting an Excel file to JSON format can be useful when you want to display the data on a web page or when you need to publish the data on a public interface on the web. Using IronXL, you can easily convert an Excel file to a JSON file.
using IronXL; // Using IronXL library for Excel operations
using System;
using System.Linq;
// Load the Excel workbook
WorkBook workBook = WorkBook.Load("multiple.xlsx");
// Save the workbook's data as a JSON file
workBook.SaveAsJson("sample.json");
using IronXL; // Using IronXL library for Excel operations
using System;
using System.Linq;
// Load the Excel workbook
WorkBook workBook = WorkBook.Load("multiple.xlsx");
// Save the workbook's data as a JSON file
workBook.SaveAsJson("sample.json");
Imports IronXL ' Using IronXL library for Excel operations
Imports System
Imports System.Linq
' Load the Excel workbook
Private workBook As WorkBook = WorkBook.Load("multiple.xlsx")
' Save the workbook's data as a JSON file
workBook.SaveAsJson("sample.json")
JSON file
Exporting Excel data to different formats is essential for exchanging and sharing data in today's fast-paced digital world. With the help of the IronXL library and ASP.NET Core, developers can easily read, write, manipulate, and export Excel files to various formats such as CSV, XML, and JSON. The process of exporting data is straightforward and can be achieved in just a few lines of code. By leveraging IronXL and ASP.NET Core, developers can create robust and dynamic applications that can handle Excel data with ease and efficiency. Therefore, exporting Excel data to different formats using IronXL and ASP.NET Core can significantly enhance the functionality and usability of an application.
Additionally, the IronXL Excel library provides the following features:
Users can also benefit from Iron Suite, a Suite of five professional libraries including IronXL, IronPDF, and more.
IronXL is a powerful ASP.NET Entity Framework Core library that allows developers to read, write, and manipulate Excel files within ASP.NET Core applications. It enables data analysis, processing, and report generation with ease.
To export an Excel file to CSV using IronXL, you can load the Excel workbook with WorkBook.Load() and then use the SaveAsCsv() method to save the workbook's data as a CSV file.
The prerequisites include having Visual Studio installed, ensuring ASP.NET is set up on your system, and installing the IronXL library via the NuGet Package Manager.
IronXL can export Excel files to CSV, XML, and JSON formats.
To install IronXL using the Visual Studio command line, open the Package Manager Console and enter the command: Install-Package IronXL.Excel.
Exporting Excel data to different formats like CSV, XML, or JSON facilitates data exchange and sharing across different platforms and applications, enhancing the functionality and usability of a software application.
Yes, IronXL supports Excel cell formatting, including text alignment, font size, color, and more, offering control over how cells are displayed in an Excel workbook.
Yes, you can create a new ASP.NET Core project using Visual Studio. Choose the Console Application template, provide a project name and location, and select the desired .NET Core version.
Besides exporting data, IronXL supports chart management compatible with Excel, supports popular Excel file formats, and offers cell formatting capabilities.
To export data from Excel to JSON using IronXL, load the Excel workbook with WorkBook.Load() and then use the SaveAsJson() method to save the workbook's data as a JSON file.