01.
Imports
System
02.
Imports
System.IO
03.
04.
Imports
OfficeOpenXml
05.
06.
Module
Module1
07.
08.
Sub
Main()
09.
Try
10.
Dim
outputDir
As
DirectoryInfo =
New
DirectoryInfo(
"c:\temp"
)
11.
If
Not
outputDir.Exists
Then
12.
Throw
New
Exception(
"Directory does not exist."
)
13.
End
If
14.
Dim
newFile
As
FileInfo =
New
FileInfo(outputDir.FullName +
"\Bang3Jim.xlsx"
)
15.
If
newFile.Exists
Then
16.
newFile.Delete()
17.
newFile =
New
FileInfo(outputDir.FullName +
"\Bang3Jim.xlsx"
)
18.
End
If
19.
20.
Using package
As
ExcelPackage =
New
ExcelPackage(newFile)
21.
Dim
ws
As
ExcelWorksheet = package.Workbook.Worksheets.Add(
"FunHappy"
)
22.
23.
ws.Cells(1, 1).Value =
"ID"
24.
ws.Cells(1, 2).Value =
"Girl Name"
25.
ws.Cells(1, 3).Value =
"Price"
26.
ws.Cells(1, 4).Value =
"จ่ายเพิ่ม"
27.
28.
29.
ws.Cells(
"A2"
).Value = 555
30.
ws.Cells(
"B2"
).Value =
"น้องขนนิ่ม เหมือนขนนก"
31.
ws.Cells(
"C2"
).Value = 1500
32.
33.
ws.Cells(
"A3"
).Value = 999
34.
ws.Cells(
"B3"
).Value =
"น้องขนดก เหมือนนกกะปูดตาแดง"
35.
ws.Cells(
"C3"
).Value = 3000
36.
37.
38.
ws.Cells(
"D2:D3"
).Formula =
"C2*2"
39.
package.Save()
40.
End
Using
41.
Catch
ex
As
Exception
42.
43.
End
Try
44.
End
Sub
45.
46.
End
Module