Location via proxy:   [ UP ]  
[Report a bug]   [Manage cookies]                
0% found this document useful (0 votes)
2 views

excel

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
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
2 views

excel

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
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
You are on page 1/ 2

'exportExcel()

'Try
'Dim xlApp As New 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.Application


'xlWorkBook = xlApp.Workbooks.Add(misValue)
'xlWorkSheet = xlWorkBook.Sheets("sheet1")
'If xlWorkBook Is Nothing Then
' MsgBox("")
'End If

'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("F:\vbexcel.xlsx")
'xlWorkBook.Close()
'xlApp.Quit()

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

'MsgBox("You can find the file F:\vbexcel.xlsx")


'Catch

'End Try

'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.Application


'xlWorkBook = xlApp.Workbooks.Add(misValue)
'xlWorkSheet = xlWorkBook.Sheets("sheet1")
'xlWorkSheet.Columns.AutoFit()
'For i = 0 To DataGridView1.RowCount - 2
' For j = 0 To DataGridView1.ColumnCount - 1
' xlWorkSheet.Cells(i + 1, j + 1) = _
' DataGridView1(j, i).Value.ToString()
' Next
'Next

'xlWorkSheet.SaveAs("C:\vbexcel.xlsx")
'xlWorkBook.Close()
'xlApp.Quit()

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

'Dim fnam As String = "Export"


'Using std As New SaveFileDialog
' std.Title = "Save As"
' std.OverwritePrompt = True
' std.FileName = fnam
' std.DefaultExt = ".xlsx"
' std.Filter = "Excel workbook(*.xlsx)|"
' std.AddExtension = True
' If std.ShowDialog() = DialogResult.OK Then
' xlWorkSheet.SaveAs(std.FileName)
' xlWorkBook.Close()
' xlApp.Quit()
' releaseObject(xlApp)
' releaseObject(xlWorkBook)
' releaseObject(xlWorkSheet)
' MsgBox("Successfully Export!", MsgBoxStyle.Information)
' End If

'End Using
'MsgBox("You can find the file C:\vbexcel.xlsx")

You might also like