Export Datagridview to Excel
Language:
Visitors have accessed this post 36300 times.
Export Datagridview to Excel + Simple Database Query( Add, update, Delete, Search)
Hope You Like It Guys :)
Note: Due to the size or complexity of this submission, the author has submitted it as a .zip file to shorten your download time. After downloading it, you will need a program like Winzip to decompress it.
Virus note: All files are scanned once-a-day by SourceCodester.com for viruses, but new viruses come out every day, so no prevention program can catch 100% of them.
FOR YOUR OWN SAFETY, PLEASE:
1. Re-scan downloaded files using your personal virus checker before using it.
2. NEVER, EVER run compiled files (.exe's, .ocx's, .dll's etc.)--only run source code.
Comments
uzumakicat (not verified)
Mon, 02/06/2012 - 14:36
Permalink
thanks for this code. me
thanks for this code. me project kasi ako...our client ask for excel. ... and i look for tutorials sa ibat ibang sites. thanks =D
Anonymous (not verified)
Sat, 10/22/2011 - 14:52
Permalink
is it possible to export data from datagrid to mysql ?
i am trying to import the data from excel into datagrid view and all those values should be updated in mysql...is it possible??
Anonymous (not verified)
Fri, 12/31/2010 - 15:26
Permalink
EXPORT DATAGRIDVIEW to EXCEL 100% WORKING CODE
TRY THIS CODE ITS 100% working
Code below creates Excel File and saves it in D: drive
It uses Microsoft office 2007
FIRST ADD REFERRANCE (Microsoft office 12.0 object library ) to your project
Then Add code given bellow to the Export button click event-
Private Sub Export_Button_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles EXPORT_Button.Click
Dim xlApp As Microsoft.Office.Interop.Excel.Application
Dim xlWorkBook As Microsoft.Office.Interop.Excel.Workbook
Dim xlWorkSheet As Microsoft.Office.Interop.Excel.Worksheet
Dim misValue As Object = System.Reflection.Missing.Value
Dim i As Integer
Dim j As Integer
xlApp = New Microsoft.Office.Interop.Excel.ApplicationClass
xlWorkBook = xlApp.Workbooks.Add(misValue)
xlWorkSheet = xlWorkBook.Sheets("sheet1")
For i = 0 To DataGridView1.RowCount - 2
For j = 0 To DataGridView1.ColumnCount - 1
For k As Integer = 1 To DataGridView1.Columns.Count
xlWorkSheet.Cells(1, k) = DataGridView1.Columns(k - 1).HeaderText
xlWorkSheet.Cells(i + 2, j + 1) = DataGridView1(j, i).Value.ToString()
Next
Next
Next
xlWorkSheet.SaveAs("D:\vbexcel.xlsx")
xlWorkBook.Close()
xlApp.Quit()
releaseObject(xlApp)
releaseObject(xlWorkBook)
releaseObject(xlWorkSheet)
MsgBox("You can find the file D:\vbexcel.xlsx")
End Sub
Private Sub releaseObject(ByVal obj As Object)
Try
System.Runtime.InteropServices.Marshal.ReleaseComObject(obj)
obj = Nothing
Catch ex As Exception
obj = Nothing
Finally
GC.Collect()
End Try
End Sub
Anonymous (not verified)
Sun, 10/03/2010 - 18:01
Permalink
Error code
Hello i was try to run this code but i got this error message:
Error 6 Type 'Excel.Application' is not defined. C:\Users\Administrator\Desktop\Excel\WindowsApplication1\Form1.vb 51 22 WindowsApplication1
Anonymous (not verified)
Fri, 08/27/2010 - 10:34
Permalink
all steps to do login vb2008
all steps to do login vb2008 with sql server database
Anonymous (not verified)
Fri, 08/27/2010 - 18:09
Permalink
all steps to do login vb2008 by ced
look for my work..
(login form) ????
try this.. hehe
'assume mo nalang cn = connection, dr = datareader, txtusername and txtpassword are textfield
with cmd
.connection = cn
.commandtext = "Select * from tblLogin Where Username = ''' & txtUsername.text & "' and Password = '" & txtpassword.text & "' "
end with
dr = cmd.executeReader
while dr.read
if dr.hasrows then
'allow user
else
'invalid username and password
end if
end while
Anonymous (not verified)
Wed, 07/21/2010 - 17:04
Permalink
Nice..
Coolllllll..Thank u
Anonymous (not verified)
Mon, 03/15/2010 - 22:08
Permalink
instead of excel, can you use
instead of excel, can you use as ms access?
ced
Tue, 03/16/2010 - 17:54
Permalink
wat?
wat do u mean? export datagridview to ms access?
ahmmp is dot posible? hehehe
cidfrey
Tue, 03/16/2010 - 23:35
Permalink
hahaha
Tol ang ibig sabihin nya kung pwede gumamit ng access instead of excel nyahahaha
Web / System Developer
Contacts :
09327081978
[email protected] >>> Facebook/YM
ICCT Colleges Cainta Rizal
Anonymous (not verified)
Fri, 03/26/2010 - 13:17
Permalink
hahah
hahaha toink conflict naman kasi ung comment nya hahaha
Anonymous (not verified)
Sun, 03/14/2010 - 13:57
Permalink
elitely
Umm.....thanks for the sharing of code. I was looking for something like this.
ced
Tue, 03/16/2010 - 17:52
Permalink
weh
dont mention it heheh dream it code it
Add new comment