Can you please tell me how can i use this save dialog that i can directly export datagridview to excel(code below):
Code:
Dim dlg As New SaveFileDialog
dlg.DefaultExt = "xls"
dlg.FileName = ("*.xls")
I will like to have save dialog in a code below.
Code:
If (dlg.ShowDialog <> Windows.Forms.DialogResult.OK) Then
Return
End If
Dim wapp As Microsoft.Office.Interop.Excel.Application
Dim wsheet As Microsoft.Office.Interop.Excel.Worksheet
Dim wbook As Microsoft.Office.Interop.Excel.Workbook
wapp = New Microsoft.Office.Interop.Excel.Application
wapp.Visible = True
wbook = wapp.Workbooks.Add()
wsheet = wbook.ActiveSheet
Dim iX As Integer
Dim iY As Integer
Dim iC As Integer
For iC = 0 To DataGridView1.Columns.Count - 1
wsheet.Cells(1, iC + 1).Value = DataGridView1.Columns(iC).HeaderText
wsheet.Cells(1, iC + 1).font.bold = True
Next
wsheet.Rows(2).select()
For iX = 0 To DataGridView1.Rows.Count - 1
For iY = 0 To DataGridView1.Columns.Count - 1
wsheet.Cells(iX + 2, iY + 1).value = DataGridView1(iY, iX).Value.ToString
Next
Next
wapp.Visible = True
wapp.UserControl = True
Thanks for your help!