Export DataTable Object To Excel File Using VB - Net in VB
Export DataTable Object To Excel File Using VB - Net in VB
com/Export-DataTable-object-to-b3e2c1f0
MSDN Magazine
Office
Faculty Connection
More...
Microsoft Student
United States (English) Newsletter Privacy & cookies Terms of Use Trademarks © 2013 Microsoft
Hirendra Sisodiya Topics Excel, VB.Net, COM Interop, DataTable, Data Export
PSPL Report abuse to Microsoft
www.authorcode.com
3,610 Points 0 2 13 Description Browse code Q and A
1 of 3 16/08/2013 1:14 PM
Export DataTable object to Excel file using vb.net in VB.NET for Visual S... http://code.msdn.microsoft.com/Export-DataTable-object-to-b3e2c1f0
Introduction
The sample applciation demonstrates that how you can export the datatable object in c# to excel format.
How to use
1. Download the sample project.
Description
Let's say we have a datatable object that contains the emoloyees' details ( employee id, name and age). And we need to
export this data to an excel file. For it firstly i create a datatable object of the employees' details at runtime. I am using
DataGrodVoew cxontrol to show this data with the help of its DataSource property.
The sample application allows you to chosse the your excel file name and the option for inserting the column names in to
excel file ot not.
Code
Create the datatable and set datasource to datagridview.
The following code shows how to create the data table object at runtime.
Visual Basic
dt.Rows.Add()
dt.Rows(0)(0) = "1"
dt.Rows(0)(1) = "David"
dt.Rows.Add()
dt.Rows(1)(0) = "2"
dt.Rows(1)(1) = "Ram"
dt.Rows.Add()
dt.Rows(2)(0) = "3"
dt.Rows(2)(1) = "John"
Return dt
End Function
Exmport to Excel
Visual Basic
End If
Dim _excel As New Excel.Application
Dim wBook As Excel.Workbook
Dim wSheet As Excel.Worksheet
wBook = _excel.Workbooks.Add()
wSheet = wBook.ActiveSheet()
2 of 3 16/08/2013 1:14 PM
Export DataTable object to Excel file using vb.net in VB.NET for Visual S... http://code.msdn.microsoft.com/Export-DataTable-object-to-b3e2c1f0
3 of 3 16/08/2013 1:14 PM