Private Sub report()
Try
Dim i As Integer = 0
Dim j As Integer = 1
Dim ExcelApp As Excel.Application
Dim ExcelBooks As Excel.Workbook
Dim ExcelSheets As Excel.Worksheet
ExcelApp = New Excel.Application
Dim chartRange As Excel.Range
ExcelApp.Visible = True
ExcelBooks = ExcelApp.Workbooks.Add()
ExcelSheets = DirectCast(ExcelBooks.Worksheets(1), Excel.Worksheet)
conn.Close()
conn.Open()
With ExcelSheets
.Columns.Font.Name = "Angsana New"
.Columns.Font.Size = 15
.Columns().ColumnWidth = 19
Dim name As String
Dim lname As String
Dim user As String
Dim pass As String
For i = 0 To GridView1.Rows.Count - 1
name = GridView1.Rows(i).Cells(1).Text
lname = GridView1.Rows(i).Cells(2).Text
user = (GridView1.Rows(i).Cells(3).Text)
pass = (GridView1.Rows(i).Cells(4).Text)
.Range("A" & j.ToString()).Value = "คุณ" + name + " " + lname
.Range("A" & j.ToString()).HorizontalAlignment = Excel.XlHAlign.xlHAlignLeft
.Range("B" & j.ToString()).Value = "Username : " + user
.Range("B" & j.ToString()).HorizontalAlignment = Excel.XlHAlign.xlHAlignLeft
.Range("C" & j.ToString()).Value = "Password : " + pass
.Range("C" & j.ToString()).HorizontalAlignment = Excel.XlHAlign.xlHAlignLeft
j += 1
Next