01.
<%
02.
Dim
objFSO,oFiles
03.
Dim
sFileName
04.
05.
//คำสั่ง
Select
06.
07.
If
Not
RS.EOF
Then
08.
09.
Set
objFSO = CreateObject(
"Scripting.FileSystemObject"
)
10.
xlsFileName = Day(Now)&Month(Now)&Year(Now)&
"_report.xls"
11.
Set
oFiles = objFSO.CreateTextFile(Server.MapPath(
"report/"
&xlsFileName), true)
12.
i=0
13.
i=i+1
14.
oFiles.WriteLine(
"<html><body>"
)
15.
oFiles.WriteLine(
"<table border="
"1"
">"
)
16.
oFiles.WriteLine(
"<tr>"
)
17.
oFiles.WriteLine(
"<th nowrap>#</th>"
)
18.
oFiles.WriteLine(
"<th nowrap></th>"
)
19.
oFiles.WriteLine(
"<th nowrap></th>"
)
20.
oFiles.WriteLine(
"<th nowrap></th>"
)
21.
oFiles.WriteLine(
"</tr>"
)
22.
While
Not
objSelect.EOF
23.
oFiles.WriteLine(
"<tr>"
)
24.
oFiles.WriteLine(
"<td align="
"Left"
" nowrap>"
& i &
"</td>"
)
25.
oFiles.WriteLine(
"<td align="
"Left"
" nowrap>"
& &
"</td>"
)
26.
oFiles.WriteLine(
"<td align="
"Left"
" nowrap>"
& RS &
"</td>"
)
27.
oFiles.WriteLine(
"<td align="
"Left"
" nowrap>"
& RS &
"</td>"
)
28.
oFiles.WriteLine(
"</tr>"
)
29.
objSelect.MoveNext()
30.
Wend
31.
oFiles.WriteLine(
"</table></body></html>"
)
32.
oFiles.Close()
33.
Set
oFiles =
Nothing
34.
Set
objFSO =
Nothing
35.
Response.write
"<a href='report/"
&xlsFileName&
"' ><img src='../icon/excel.png' title='Download' style='margin: 0 0 0 37px'></a>"
&
"<br>"
&
"<br>"
36.
Else
37.
Response.write
"<script type='text/javascript'>alert('ไม่พบข้อมูลที่ค้นหา');window.close(); </script>"
38.
End
If
39.
40.
objSelect.Close()
41.
Set
objSelect =
Nothing
42.
%>