Export Datagridview to Excel
Friday, February 5, 2010 - 13:25
Language:
Visitors have accessed this post 12987 times.

Export Datagridview to Excel + Simple Database Query( Add, update, Delete, Search)
Hope You Like It Guys :)
Download Code:
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
elitely
Umm.....thanks for the sharing of code. I was looking for something like this.
weh
dont mention it heheh dream it code it
instead of excel, can you use
instead of excel, can you use as ms access?
wat?
wat do u mean? export datagridview to ms access?
ahmmp is dot posible? hehehe
hahaha
Tol ang ibig sabihin nya kung pwede gumamit ng access instead of excel nyahahaha
Web / System Developer
Contacts :
09327081978
recca_flame05@yahoo.com >>> Facebook/YM
ICCT Colleges Cainta Rizal
hahah
hahaha toink conflict naman kasi ung comment nya hahaha
Nice..
Coolllllll..Thank u
all steps to do login vb2008
all steps to do login vb2008 with sql server database
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
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
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
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??
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
Add new comment