Private Sub Exportbtt_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Exportbtt.Click
Dim xlApp As excel.Application
Dim xlWorkBook As excel.Workbook
Dim xlWorkSheet As excel.Worksheet
Dim i As Integer
Dim j As Integer
Dim misValue As Object = System.Reflection.Missing.Value
xlApp = New excel.Application
xlWorkBook = xlApp.Workbooks.Add(misValue)
xlWorkSheet = xlWorkBook.Sheets("sheet1")
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()
If TbUser.Text <> Nothing And TbPass.Text <> Nothing Then
TbUser.Focus()
If TbWorkSheet.Text <> Nothing Then
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()
Dim saveFileDialog1 As System.Windows.Forms.SaveFileDialog
saveFileDialog1 = New System.Windows.Forms.SaveFileDialog()
saveFileDialog1.Filter = "Excel (*.xls) |*.xls;"
If saveFileDialog1.ShowDialog() = DialogResult.OK Then
xlWorkSheet.SaveAs(saveFileDialog1.FileName)
End If
Private Sub Exportbtt_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Exportbtt.Click
Dim xlApp As excel.Application
Dim xlWorkBook As excel.Workbook
Dim xlWorkSheet As excel.Worksheet
Dim i As Integer
Dim j As Integer
Dim misValue As Object = System.Reflection.Missing.Value
xlApp = New excel.Application
xlWorkBook = xlApp.Workbooks.Add(misValue)
xlWorkSheet = xlWorkBook.Sheets("sheet1")
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
Dim saveFileDialog1 As System.Windows.Forms.SaveFileDialog
saveFileDialog1 = New System.Windows.Forms.SaveFileDialog()
saveFileDialog1.Filter = "Excel (*.xls) |*.xls;"
If saveFileDialog1.ShowDialog() = DialogResult.OK Then
xlWorkSheet.SaveAs(saveFileDialog1.FileName)
MsgBox("export ข้อมูลเรียบร้อยแล้ว")
End If
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()