1, ASP file:
<%@ language= "VBSCRIPT"%>
<%option explicit%>
<%
' EXAMPLE as: Put a 24-hour online number in the database into an Excel file
' AUTHOR: Steel Workers
' Email:hello_hhb@21cn.com
' Date:2001-3-25
' Test: Testing through in Nt4,sp6,sql SERVER 7.0,excel2000
%>
<HTML>
<HEAD>
<meta content= "text/html; charset=gb2312 "http-equiv=" Content-type ">
<TITLE> Generate Excel File </TITLE>
</HEAD>
<body>
<a href= "Dbtoexcel.asp?act=make" > Generation of online population excel</a>
<HR size=1 Align=left width=300px>
<%
If Request ("act") = "" Then
Else
Dim conn
Set Conn=server. CreateObject ("Adodb.connection")
Conn. Open "Test", "sa", ""
' Conn. Open application ("ConnStr")
Dim Rs,sql,filename,fs,myfile,x,link
Set fs = server. CreateObject ("Scripting.FileSystemObject")
'--suppose you want the resulting Excel file to be stored as follows
filename = "C:online.xls"
'--delete it if the original Excel file exists
If Fs. FileExists (filename) Then
Fs. DeleteFile (filename)
End If
'--Create Excel file
Set myfile = fs. CreateTextFile (Filename,true)
Set rs = Server.CreateObject ("ADODB.") Recordset ")
'--Find out from the database the data you want to put in Excel
sql = "Select Population,hourpos,datepos from Populationperhour ORDER by datepos,hourpos ASC"
Rs. Open Sql,conn
If Rs. EOF and Rs. BOF Then
Else
Dim strline,responsestr
Strline= ""
For each x in Rs.fields
Strline= StrLine & X.name & Chr (9)
Next
'--Writes the table's column name first to Excel
MyFile.WriteLine StrLine
Do but not Rs. Eof
Strline= ""
For each x in Rs. Fields
Strline= StrLine & X.value & Chr (9)
Next
'--Writes the table's data to Excel
MyFile.WriteLine StrLine
The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion;
products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the
content of the page makes you feel confusing, please write us an email, we will handle the problem
within 5 days after receiving your email.
If you find any instances of plagiarism from the community, please send an email to:
info-contact@alibabacloud.com
and provide relevant evidence. A staff member will contact you within 5 working days.