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
DataTables handle large data sets with sorting, filtering, and search options. They can be exported to Excel for visual presentations, like charts and graphs, for richer data insight. HTML tables can also be converted to Excel workbooks.
IronXL is a powerful library designed to facilitate the creation, reading, and manipulation of Excel files in VB.NET applications. With IronXL, developers can quickly and easily incorporate Excel worksheet functionality into their applications without requiring any specialized knowledge or expertise in Excel sheets. The library provides a range of features for working with Excel files, including the ability to read and write data, format cells, create charts and graphs, and much more. IronXL supports both XLS and XLSX file formats and can be used with a variety of Excel versions. Using IronXL you can also add column headers in .NET code.
To successfully write code using IronXL in VB.NET, several prerequisites must be in place:
Ensuring that these prerequisites are met will enable you to write code successfully using IronXL in VB.NET.
To create VB.NET in Visual Studio, follow these steps to create a VB.NET project in Visual Studio:
Choose the type of project you want to create, such as "Windows Forms App" or "Console App". This tutorial will use a Console App.
Create a new project in Visual Studio
Enter a name for your project and choose a location to save it.
Configure your project
Then select the .NET Core version and click on "Create".
.NET Framework selection
You are now ready to start writing your VB.NET code in Visual Studio.
The IronXL Library can be downloaded and installed in different ways:
To install the IronXL library, the first approach is to use the NuGet Package Manager in Visual Studio. Simply open the NuGet Package Manager and search for IronXL in the Browse tab. Once you have located IronXL in the search results, select it and proceed with the installation.
The below screenshot shows an example of how to navigate to the NuGet Package Manager in Visual Studio.
Navigate to the NuGet Package Manager
IronXL in search results:
Search and install the IronXL package in NuGet Package Manager UI
Many people prefer to install packages using the command line interface. To install IronXL using the command line, follow these steps:
Install-Package IronXL.Excel
Now the package will download/install to the current project and be ready to use.
Install IronXL package in Package Manager Console
The process of exporting a DataTable to an Excel file is a common task in data processing, and IronXL makes it easy to accomplish this in VB.NET. First, you need to create a new DataTable with the data you want to export. Then, you can use IronXL's Workbook object to create a new Excel workbook and add a worksheet to it. After that, you can populate the worksheet with the DataTable columns' data using IronXL's Range object.
Exporting a DataTable object to an XLS file allows you to save the table data in a format that is easily readable and shareable with others while preserving the structure and formatting of the original data.
The following code snippet shows how you can create DataTable rows and convert them into an Excel file.
Imports IronXL
Imports System
Imports System.Data
Module Program
Sub Main(args As String())
' Create a new DataTable
Dim table As New DataTable()
' Add a column to the DataTable
table.Columns.Add("DataSet_Daily_Household", GetType(String))
' Add rows to the DataTable
table.Rows.Add("Glass")
table.Rows.Add("Plates")
table.Rows.Add("Match Sticks")
table.Rows.Add("Leather")
table.Rows.Add("Soap")
table.Rows.Add("Brush")
table.Rows.Add("Comb")
table.Rows.Add("Wires")
table.Rows.Add("Pins")
table.Rows.Add("And Many More")
' Create a new Excel workbook and set the format to XLS
Dim dt As WorkBook = WorkBook.Create(ExcelFileFormat.XLS)
' Select the default worksheet
Dim dc As WorkSheet = dt.DefaultWorkSheet
' Iterate through DataTable rows and populate the Excel worksheet
Dim rowCount As Integer = 1
For Each row As DataRow In table.Rows
dc("A" & (rowCount)).Value = row(0).ToString()
rowCount += 1
Next row
' Save the workbook as "sample.xls"
dt.SaveAs("sample.xls")
End Sub
End Module
Imports IronXL
Imports System
Imports System.Data
Module Program
Sub Main(args As String())
' Create a new DataTable
Dim table As New DataTable()
' Add a column to the DataTable
table.Columns.Add("DataSet_Daily_Household", GetType(String))
' Add rows to the DataTable
table.Rows.Add("Glass")
table.Rows.Add("Plates")
table.Rows.Add("Match Sticks")
table.Rows.Add("Leather")
table.Rows.Add("Soap")
table.Rows.Add("Brush")
table.Rows.Add("Comb")
table.Rows.Add("Wires")
table.Rows.Add("Pins")
table.Rows.Add("And Many More")
' Create a new Excel workbook and set the format to XLS
Dim dt As WorkBook = WorkBook.Create(ExcelFileFormat.XLS)
' Select the default worksheet
Dim dc As WorkSheet = dt.DefaultWorkSheet
' Iterate through DataTable rows and populate the Excel worksheet
Dim rowCount As Integer = 1
For Each row As DataRow In table.Rows
dc("A" & (rowCount)).Value = row(0).ToString()
rowCount += 1
Next row
' Save the workbook as "sample.xls"
dt.SaveAs("sample.xls")
End Sub
End Module
The Excel file generated from the code snippet above
Similarly, for converting DataTable rows and columns to XLSX file format, just change one line of code in the above example.
Replace this line of code:
dt.SaveAs("sample.xls")
dt.SaveAs("sample.xls")
With this:
dt.SaveAs("sample.xlsx")
dt.SaveAs("sample.xlsx")
You can also convert DataTable rows and columns to CSV file format by changing one line of code in the above example from SaveAs
to SaveAsCsv
.
Replace this line of code:
dt.SaveAs("sample.xls")
dt.SaveAs("sample.xls")
With this:
dt.SaveAsCsv("sample.csv")
dt.SaveAsCsv("sample.csv")
The CSV file generated from the code above
Exporting a DataTable
to an Excel file in VB.NET is a common requirement in data processing and analysis. The IronXL library provides developers with a powerful tool to facilitate the creation, reading, and manipulation of Excel files in VB.NET applications, including the ability to export DataTables
to Excel files. By exporting DataTables
to Excel files, users can leverage the powerful features provided by Excel, such as charts, graphs, and pivot tables, to present data in a visually appealing and organized manner. To use IronXL, you need to ensure that you have met the prerequisites, such as having Visual Studio and the .NET Framework installed and installing the IronXL library. Finally, this tutorial demonstrated how to export DataTables
to Excel files in both XLS and CSV file formats using IronXL.
To learn more about exporting DataTables
to Excel files using IronXL, please visit this provided tutorial.
Furthermore, users can utilize Iron Suite, a bundle of five high-quality ASP.NET Core libraries that include IronXL, IronPDF, and other components.
IronXL is a powerful library designed to facilitate the creation, reading, and manipulation of Excel files in VB.NET applications. It allows developers to incorporate Excel functionality without specialized expertise in Excel.
To use IronXL in VB.NET, you must have Visual Studio installed, the .NET Framework version 4.0 or later, and the IronXL library installed in your project.
To create a VB.NET project in Visual Studio, open the software, click 'Create a new project', select 'Visual Basic', choose a project type, name your project, and select the .NET Core version.
IronXL can be installed using the NuGet Package Manager in Visual Studio or via the Visual Studio Command Line by entering 'Install-Package IronXL.Excel' in the Package Manager Console.
To export a DataTable to an Excel file using IronXL, create a DataTable, use IronXL's Workbook object to create an Excel workbook, add a worksheet, and populate it with DataTable data using IronXL's Range object.
Yes, IronXL allows exporting DataTables to XLS, XLSX, and CSV file formats by modifying the SaveAs method in the code.
IronXL supports both XLS and XLSX file formats, allowing developers to work with a variety of Excel versions.
IronXL provides features such as reading and writing data, formatting cells, creating charts and graphs, and converting between spreadsheet file types.
For more tutorials on using IronXL, including how to export DataTables to Excel files, visit the provided IronXL tutorials on the official website.
The Iron Suite is a bundle of five high-quality ASP.NET Core libraries, including IronXL and IronPDF, designed to enhance application features and functionalities.