Export Datatable To Excel in VB
Export Datatable To Excel in VB
Net
Problem
Some time in your application there is need to export the data table into Excel
worksheet.
Example
wBook = _excel.Workbooks.Add()
wSheet = wBook.ActiveSheet()
wBook.SaveAs(strFileName)
wBook.Close()
_excel.Quit()
End Sub
In the above code we are reading the values of every item of every rows and put into the
cell of the excel. With the same process you can also export the data of the datagridview
control into the excel file.
Before using the above code you will need to add the refernce of the this library, Do the
following these steps:
1. On the Project menu, click Add Reference.
2. On the COM tab, locate Microsoft Excel Object Library, and then click
Select.
3. Click OK in the Add References dialog box to accept your selections. If you are
prompted to generate wrappers for the libraries that you selected, click “Yes”.
Sumber : http://www.authorcode.com/export-datatable-to-excel-in-vb-net/