01.
Private
Sub
report()
02.
03.
Dim
i
As
Integer
= 0
04.
Dim
j
As
Integer
= 5
05.
06.
Dim
i2
As
Integer
= 0
07.
Dim
j2
As
Integer
= 5
08.
Dim
ExcelApp
As
Excel.Application
09.
Dim
ExcelBooks
As
Excel.Workbook
10.
Dim
ExcelSheets
As
Excel.Worksheet
11.
12.
ExcelApp =
New
Excel.Application
13.
Dim
chartRange
As
Excel.Range
14.
15.
16.
ExcelApp.Visible =
True
17.
ExcelBooks = ExcelApp.Workbooks.Add()
18.
ExcelSheets =
DirectCast
(ExcelBooks.Worksheets(1), Excel.Worksheet)
19.
ExcelSheets.Name =
"กรมธรรม์"
20.
21.
22.
Dim
CurrentThread
As
System.Threading.Thread
23.
CurrentThread = System.Threading.Thread.CurrentThread
24.
CurrentThread.CurrentCulture =
New
CultureInfo(
"en-US"
)
25.
CurrentThread.CurrentCulture =
New
CultureInfo(
"th-TH"
)
26.
27.
28.
Dim
dsChk
As
New
DataSet
29.
Dim
sqlselect
As
String
=
""
30.
Dim
idagent
As
String
=
""
31.
Dim
addagent
As
String
=
""
32.
33.
With
ExcelSheets
34.
35.
36.
chartRange = ExcelSheets.Range(
"A1"
,
"I1"
)
37.
chartRange.Merge()
38.
chartRange.FormulaR1C1 =
"รายงานแสดงรายละเอียดกรมธรรม์ทั้งหมด"
39.
chartRange.HorizontalAlignment = 3
40.
chartRange.VerticalAlignment = 3
41.
42.
chartRange = ExcelSheets.Range(
"A2"
,
"I2"
)
43.
chartRange.Merge()
44.
chartRange.FormulaR1C1 =
"บริษัท ทิพยประกันภัย จำกัด ศูนย์ ระยอง"
45.
chartRange.HorizontalAlignment = 3
46.
chartRange.VerticalAlignment = 3
47.
48.
49.
50.
51.
52.
.Range(
"A1"
).Font.Size = 20
53.
.Range(
"A2"
).Font.Size = 16
54.
55.
56.
.Range(
"A4"
).Value =
"บริษัท"
57.
.Range(
"A4"
).Borders.LineStyle =
True
58.
.Range(
"A4"
).Font.Bold =
True
59.
.Range(
"A4"
).HorizontalAlignment = Excel.XlHAlign.xlHAlignCenter
60.
61.
.Range(
"B4"
).Value =
"ชื่อโรงเรียน"
62.
.Range(
"B4"
).Borders.LineStyle =
True
63.
.Range(
"B4"
).Font.Bold =
True
64.
.Range(
"B4"
).HorizontalAlignment = Excel.XlHAlign.xlHAlignCenter
65.
66.
67.
Dim
t0
As
String
68.
Dim
t1
As
String
69.
70.
For
i = 0
To
DataGridView_Branch.Rows.Count - 2
71.
t0 =
CStr
(DataGridView_Branch.Rows(i).Cells(0).Value.ToString)
72.
73.
t1 =
CStr
(DataGridView_Branch.Rows(i).Cells(1).Value.ToString)
74.
75.
76.
.Range(
"A"
& j.ToString()).Value = t0.ToString
77.
.Range(
"A"
& j.ToString()).Borders.LineStyle =
True
78.
.Range(
"A"
& j.ToString()).HorizontalAlignment = Excel.XlHAlign.xlHAlignCenter
79.
80.
81.
.Range(
"B"
& j.ToString()).Value = t1.ToString
82.
.Range(
"B"
& j.ToString()).Borders.LineStyle =
True
83.
.Range(
"B"
& j.ToString()).HorizontalAlignment = Excel.XlHAlign.xlHAlignCenter
84.
85.
j += 1
86.
Next
87.
chartRange = ExcelSheets.Range(
"A5"
,
"A"
& j.ToString() - 1)
88.
chartRange.BorderAround(Excel.XlLineStyle.xlContinuous, _
89.
Excel.XlBorderWeight.xlThin, Excel.XlColorIndex. _
90.
xlColorIndexAutomatic, Excel.XlColorIndex.xlColorIndexAutomatic)
91.
92.
chartRange = ExcelSheets.Range(
"B5"
,
"B"
& j.ToString() - 1)
93.
chartRange.BorderAround(Excel.XlLineStyle.xlContinuous, _
94.
Excel.XlBorderWeight.xlThin, Excel.XlColorIndex. _
95.
xlColorIndexAutomatic, Excel.XlColorIndex.xlColorIndexAutomatic)
96.
97.
98.
End
With