Dim xlApp As New Excel.Application
Dim xlSheet1As Excel.Worksheet
Dim xlBook As Excel.Workbook
xlBook = xlApp.Workbooks.Add()
xlBook.Application.Visible = False
xlSheet1 = xlBook.Worksheets(1)
xlSheet1.Name = "My Sheet1"
'ความกว้าง
With xlApp.ActiveSheet.Range("A1:A1")
.ColumnWidth = 7.75
End With
With xlApp.ActiveSheet.Range("B1:B1")
.ColumnWidth = 20.63
End With
With xlApp.ActiveSheet.Cells(1, 1)
.Value = lcRptName
End With
'ส่วนหัว
With xlApp.ActiveSheet.Cells(2, 1)
.Value = "เดือน"
.Font.Bold = True
.Font.Size = 10
.VerticalAlignment = -4108
.HorizontalAlignment = -4108
End With
'ข้อมูล
With xlApp.ActiveSheet.Cells(lnCmonth, 1)
.Value = dgvShow.Item(0, i).Value
.BORDERS.Weight = 2
.HorizontalAlignment = -4131
End With
With xlApp.ActiveSheet.Cells(lnCmonth, 2)
.Value = dgvShow.Item(1, i).Value
.BORDERS.Weight = 2
.HorizontalAlignment = -4131
End With
MyFile = Nothing
xlSheet1.SaveAs(filePath)
xlApp.Quit()
xlSheet1 = Nothing
xlBook = Nothing
xlApp = Nothing