Hi,
Private Sub btn_excel_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btn_excel.Click
Dim xlapp As Excel.Application
Dim xlworkbook As Excel.Workbook
Dim xlworksheet As Excel.Worksheet
Dim misvalue As Object = System.Reflection.Missing.Value
Dim i As Integer
Dim j As Integer
xlapp = New Excel.Application
xlworkbook = xlapp.Workbooks.Add(misvalue)
xlworksheet = xlworkbook.Sheets("Sheet1")
For i = 0 To gv.RowCount - 2
For j = 0 To gv.ColumnCount - 1
xlworksheet.Cells(i + 1, j + 1) = _
gv(j, i).Value.ToString()
Next
Next
Dim dialog As New SaveFileDialog
Dim result As DialogResult = dialog.ShowDialog
Try
xlworksheet.SaveAs(dialog.FileName)
Catch exerr As Exception
End Try
xlworkbook.Close()
xlapp.Quit()
releaseObject(xlapp)
releaseObject(xlworkbook)
releaseObject(xlworksheet)
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