<% Option Explicit %>
<html>
<head>
<title>ThaiCreate.Com ASP Excel.Application Tutorial</title>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8"></head>
<body>
<%
Dim Conn,strSQL,objRec
Dim xlApp,xlBook,xlSheet1,FileName,intRows
Dim Fso,MyFile
Set Conn = Server.Createobject("ADODB.Connection")
Conn.Open "DRIVER=Microsoft Access Driver (*.mdb);DBQ=" & Server.MapPath("mydatabase.mdb"),"" , ""
'strSQL = "SELECT * FROM customer where customername"
strSQL = "SELECT * FROM customer WHERE datedata ='"& Request.QueryString("CusID")&"' "
'strSQL = "SELECT * FROM customer"
'strSQL = strSQL & "WHERE (datedata LIKE '%"& Request.QueryString("CusID") &"%') "
Set objRec = Conn.Execute(strSQL)
'End IF
Set objRec = Server.CreateObject("ADODB.Recordset")
objRec.Open strSQL, Conn, 1,3
'Set Conn = Server.Createobject("ADODB.Connection")
'Conn.Open "DRIVER=Microsoft Access Driver (*.mdb);DBQ=" & Server.MapPath("mydatabase.mdb"),"" , ""
'strSQL = "SELECT * FROM customer where datedata"
'strSQL = "SELECT * FROM customer where datedata LIKE '%"& Request.QueryString("date") &"%'"
'Set objRec = Server.CreateObject("ADODB.Recordset")
'objRec.Open strSQL, Conn, 1,3
If Not objRec.EOF Then
FileName = "MyXls.xls "
'*** Create Exce.Application ***'
Set xlApp = Server.CreateObject("Excel.Application")
Set xlBook = xlApp.Workbooks.Add
'*** Create Sheet 1 ***'
xlBook.Worksheets(1).Name = "My Customer"
xlBook.Worksheets(1).Select
'*** Header ***'
With xlApp.ActiveSheet.Cells(1,1)
.Value = "CustomerID"
End With
With xlApp.ActiveSheet.Cells(1,2)
.Value = "Name"
End With
With xlApp.ActiveSheet.Cells(1,3)
.Value = "Email"
End With
With xlApp.ActiveSheet.Cells(1,4)
.Value = "CountryCode"
End With
With xlApp.ActiveSheet.Cells(1,5)
.Value = "Budget"
End With
With xlApp.ActiveSheet.Cells(1,6)
.Value = "Used"
End With
'***********'
intRows = 2
While Not objRec.EOF
'*** Detail ***'
With xlApp.ActiveSheet.Cells(intRows,1)
.Value = objRec.Fields("Customername").Value
End With
With xlApp.ActiveSheet.Cells(intRows,2)
.Value = objRec.Fields("datedata").Value
End With
With xlApp.ActiveSheet.Cells(intRows,3)
.Value = objRec.Fields("action").Value
End With
With xlApp.ActiveSheet.Cells(intRows,4)
.Value = objRec.Fields("user").Value
End With
With xlApp.ActiveSheet.Cells(intRows,5)
.Value = objRec.Fields("card").Value
End With
With xlApp.ActiveSheet.Cells(intRows,6)
.Value = objRec.Fields("teluser").Value
End With
intRows = intRows + 1
objRec.MoveNext
Wend
'*** 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 ***'
'xlBook.PrintOut 1 '*** Print to printer ***'
xlBook.SaveAs Server.MapPath(FileName)
xlApp.Application.Quit
'*** Quit and Clear Object ***'
Set xlSheet1 = Nothing
Set xlBook = Nothing
Set xlApp = Nothing
End If
objRec.Close()
Conn.Close()
Set objRec = Nothing
Set Conn = Nothing
%>
Excel Created<a href="<%=FileName%>">Click here</a> to Download.
</body>
</html>