<% Option Explicit %>
<html>
<head>
<title>ThaiCreate.Com ASP Excel.Application Tutorial</title>
</head>
<body>
<%
Dim xlApp,xlBook,xlSheet1,FileName
Dim Fso,MyFile
FileName = "MyXls/MyExcel.xls"
'*** Create Exce.Application ***'
Set xlApp = Server.CreateObject("Excel.Application")
Set xlBook = xlApp.Workbooks.Add
'*** Create Sheet 1 ***'
Set xlSheet1 = xlBook.Worksheets(1)
xlSheet1.Name = "My Sheet1"
xlApp.Application.Visible = False
'*** Write text to Row 1 Column 1 ***'
With xlApp.ActiveSheet.Cells(1,1)
.Value = "ThaiCreate.Com"
End With
'*** Write text to Row 1 Column 2 ***'
With xlApp.ActiveSheet.Cells(1,2)
.Value = "Mr.Weerachai Nukitram"
End With
'*** If Files Already Exist Delete files ***'
Set Fso = CreateObject("Scripting.FileSystemObject")
If (Fso.FileExists(Server.MapPath(FileName))) Then
Set MyFile = Fso.GetFile(Server.MapPath(FileName))
MyFile.Delete
End If
'*** Save Excel ***'
'xlSheet1.PrintOut 1 '*** Print to printer ***'
xlSheet1.SaveAs Server.MapPath(FileName)
xlApp.Application.Quit
'*** Quit and Clear Object ***'
Set xlSheet1 = Nothing
Set xlBook = Nothing
Set xlApp = Nothing
%>
Excel Created <a href="<%=FileName%>">Click here</a> to Download.
</body>
</html>