01.
<%
Option
Explicit %>
02.
<html>
03.
<head>
04.
<title>ThaiCreate.Com ASP Excel.Application Tutorial</title>
05.
</head>
06.
<body>
07.
<%
08.
Dim
xlApp,xlBook,xlSheet1,FileName
09.
Dim
Fso,MyFile
10.
FileName =
"MyXls/MyExcel.xls"
11.
12.
Const
xlEdgeLeft = 7
13.
Const
xlEdgeTop = 8
14.
Const
xlEdgeBottom = 9
15.
Const
xlEdgeRight = 10
16.
17.
18.
Set
xlApp = Server.CreateObject(
"Excel.Application"
)
19.
Set
xlBook = xlApp.Workbooks.Add
20.
21.
22.
Set
xlSheet1 = xlBook.Worksheets(1)
23.
xlSheet1.Name =
"My Sheet1"
24.
xlApp.Application.Visible =
False
25.
26.
27.
With
xlApp.ActiveSheet.Cells(1,1)
28.
.Value =
"ThaiCreate.Com"
29.
End
With
30.
31.
32.
With
xlApp.ActiveSheet.Cells(1,2)
33.
.Value =
"Mr.Weerachai Nukitram"
34.
End
With
35.
36.
37.
With
xlApp.ActiveSheet.Range(
"B3:D5"
)
38.
.BORDERS.Weight = 2
39.
End
With
40.
41.
42.
With
xlApp.ActiveSheet.Range(
"B7:D9"
)
43.
.BORDERS(xlEdgeLeft).Weight = 2
44.
.BORDERS(xlEdgeTop).Weight = 2
45.
.BORDERS(xlEdgeBottom).Weight = 2
46.
.BORDERS(xlEdgeRight).Weight = 2
47.
End
With
48.
49.
50.
Set
Fso = CreateObject(
"Scripting.FileSystemObject"
)
51.
If
(Fso.FileExists(Server.MapPath(FileName)))
Then
52.
Set
MyFile = Fso.GetFile(Server.MapPath(FileName))
53.
MyFile.Delete
54.
End
If
55.
56.
57.
58.
xlSheet1.SaveAs Server.MapPath(FileName)
59.
xlApp.Application.Quit
60.
61.
62.
Set
xlSheet1 =
Nothing
63.
Set
xlBook =
Nothing
64.
Set
xlApp =
Nothing
65.
%>
66.
Excel Created <a href=
"<%=FileName%>"
>Click here</a> to Download.
67.
</body>
68.
</html>