"export datagridview to excel vb.net" Code Answer's
You're definitely familiar with the best coding language VBA that developers use to develop their projects and they get all their queries like "export datagridview to excel vb.net" answered properly. Developers are finding an appropriate answer about export datagridview to excel vb.net related to the VBA coding language. By visiting this online portal developers get answers concerning VBA codes question like export datagridview to excel vb.net. Enter your desired code related query in the search bar and get every piece of information about VBA code related question on export datagridview to excel vb.net.
export datagridview to excel vb.net
Private Sub Export_Button_Click(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles VIEW_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
Source: stackoverflow.com
All those coders who are working on the VBA based application and are stuck on export datagridview to excel vb.net can get a collection of related answers to their query. Programmers need to enter their query on export datagridview to excel vb.net related to VBA code and they'll get their ambiguities clear immediately. On our webpage, there are tutorials about export datagridview to excel vb.net for the programmers working on VBA code while coding their module. Coders are also allowed to rectify already present answers of export datagridview to excel vb.net while working on the VBA language code. Developers can add up suggestions if they deem fit any other answer relating to "export datagridview to excel vb.net". Visit this developer's friendly online web community, CodeProZone, and get your queries like export datagridview to excel vb.net resolved professionally and stay updated to the latest VBA updates.