0% found this document useful (0 votes)
24 views2 pages

Export DataGridView to Excel File

The document contains code for exporting data from a DataGridView to an Excel file using Microsoft Office Interop. It initializes an Excel application, creates a workbook and worksheet, populates the worksheet with data from the DataGridView, and saves the file to a specified location. Additionally, it includes functionality for saving the file through a SaveFileDialog, allowing the user to choose the file name and location.

Uploaded by

lkishomy02
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
24 views2 pages

Export DataGridView to Excel File

The document contains code for exporting data from a DataGridView to an Excel file using Microsoft Office Interop. It initializes an Excel application, creates a workbook and worksheet, populates the worksheet with data from the DataGridView, and saves the file to a specified location. Additionally, it includes functionality for saving the file through a SaveFileDialog, allowing the user to choose the file name and location.

Uploaded by

lkishomy02
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as TXT, PDF, TXT or read online on Scribd

'exportExcel()

'Try
'Dim xlApp As New [Link]
'Dim xlWorkBook As [Link]
'Dim xlWorkSheet As [Link]
'Dim misValue As Object = [Link]
'Dim i As Integer
'Dim j As Integer

'xlApp = New [Link]


'xlWorkBook = [Link](misValue)
'xlWorkSheet = [Link]("sheet1")
'If xlWorkBook Is Nothing Then
' MsgBox("")
'End If

'For i = 0 To [Link] - 2
' For j = 0 To [Link] - 1
' For k As Integer = 1 To [Link]
' [Link](1, k) = [Link](k -
1).HeaderText
' [Link](i + 2, j + 1) = DataGridView1(j,
i).[Link]()
' Next
' Next
'Next

'[Link]("F:\[Link]")
'[Link]()
'[Link]()

'releaseObject(xlApp)
'releaseObject(xlWorkBook)
'releaseObject(xlWorkSheet)

'MsgBox("You can find the file F:\[Link]")


'Catch

'End Try

'Dim xlApp As [Link]


'Dim xlWorkBook As [Link]
'Dim xlWorkSheet As [Link]
'Dim misValue As Object = [Link]
'Dim i As Integer
'Dim j As Integer

'xlApp = New [Link]


'xlWorkBook = [Link](misValue)
'xlWorkSheet = [Link]("sheet1")
'[Link]()
'For i = 0 To [Link] - 2
' For j = 0 To [Link] - 1
' [Link](i + 1, j + 1) = _
' DataGridView1(j, i).[Link]()
' Next
'Next

'[Link]("C:\[Link]")
'[Link]()
'[Link]()

'releaseObject(xlApp)
'releaseObject(xlWorkBook)
'releaseObject(xlWorkSheet)

'Dim fnam As String = "Export"


'Using std As New SaveFileDialog
' [Link] = "Save As"
' [Link] = True
' [Link] = fnam
' [Link] = ".xlsx"
' [Link] = "Excel workbook(*.xlsx)|"
' [Link] = True
' If [Link]() = [Link] Then
' [Link]([Link])
' [Link]()
' [Link]()
' releaseObject(xlApp)
' releaseObject(xlWorkBook)
' releaseObject(xlWorkSheet)
' MsgBox("Successfully Export!", [Link])
' End If

'End Using
'MsgBox("You can find the file C:\[Link]")

You might also like