<%
db= "Db1.mdb"
Path=server.mappath (DB)
Set Conn=server.createobject ("ADODB. Connection ")
connstr=" Provider=Microsoft.Jet.OLEDB.4.0;Data source= "&path
Conn. The Open connstr
Set rs=server. CreateObject ("Adodb.recordset")
%>
<! DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 transitional//en"
< title> New Document </title>
<meta name= "generator" content= "EditPlus"
<meta Name= "Author" content= "" "
<meta name=" Keywords "content=" "
<meta name=" Description " Content= ""
<style>
td{font-size:12px;}
</STYLE>
<script>
Function Checkall (a)
{
o =document.getelementsbyname (a)
for (i=0;i<o.length;i++)
o[i].checked= event.srcElement.checked
}
Function Fsubmit ()
{
if ("To build Excel", "Are you sure you want to generate Excel files for these records?" "," Record ") return false;
}
function F2 (text,t1,name)
{
var dnum=document.getelementsbyname ("id"). length;
j=0;
if (dnum==1)
{
if (document.form1.id.checked==true)
{
j + +;
}
}
Else
{
for (i=0;i<dnum;i++)
{
if (document.form1.id[i].checked==true)
{
j + +;
}
}
}
if (j==0)
{
Alert (' Please choose the ' +name ' you want ' +text+ ');
return false;
}
Else
{
if (!confirm (T1)) return false;
}
return true;
}
</script>
<BODY>
<table border= "1" width= "cellpadding=0 cellspacing=0>"
<form name= "Form1" method= "Post" action= "1.asp Tutorial" onsubmit= "return Fsubmit ();" >
<TR>
<TD width= "5%" height= "align=" "Center" ><input type= "checkbox" name= "checkbox" value= "checkbox" onclick= " Checkall (' id ') ' ></TD>
<TD height= "align=" "Center" > Username </TD>
<TD height= align= "center" > Password </TD>
<TD width= "40%" height= "align=" "Center" > Content </TD>
<TD align= "center" > Gender </TD>
<TD align= "center" > Release Time </TD>
</TR>
<%
Sql= "SELECT Top id,username,password,content,sex,ytime from users"
Rs.Open sql,conn,1,1
If rs.eof Then
Else
Do as not rs.eof
id = RS ("id")
Username = rs ("username")
Password = rs ("password")
Content = rs ("content")
Sex = rs ("Sex")
Ytime = RS ("Ytime")
' ****************** below is the ****************** you want to show '
%>
<TR>
<TD height= "align=" center "><input type=" checkbox "Name=" id "value=" <%=id%> "></TD>
<TD height= "><%=username%></TD>"
<TD height= "><%=password%></TD>"
<TD height= "><%=content%></TD>"
<TD height= align= "center" ><%=sex%></TD>
<TD height= "align=" "left" > <%=ytime%></TD>
</TR>
<%
' ****************** above is the ****************** you want to show '
Rs.movenext
Loop
End If
Rs.close
%>
<TR>
<TD height= "colspan=" 6 ">
<input type= "Submit" name= "submit" value= "Generate Excel File" ></TD>
</TR>
</form>
</TABLE>
</BODY>
</HTML>
1.asp file
<!--#include file= "conn.asp"-->
<%
' Function: Generate Excel file for specified records
' Author: wangsdong
The
Id=request ("id")
Set Conn =server. CreateObject ("Adodb.connection")
connstr= "Provider=Microsoft.Jet.OLEDB.4.0;Data source=" & Server.MapPath ( db)
Conn.Open connstr
Dim rs,sql,filename,fs,myfile,x
Set fs = server. CreateObject ("Scripting.FileSystemObject")
filename = Server.MapPath ("111cn.net tutorial. xls")
if FS. FileExists (filename) then
FS. DeleteFile (filename)
End If
Set myfile = fs. CreateTextFile (filename,true)
Set rs = Server.CreateObject ("ADODB. Recordset ")
sql=" Select Id,username,password,content,sex,ytime from Users where IDs in ("&id&")
Rs. Open sql,conn,1,1
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
MyFile.WriteLine strLine
Do and not Rs. EOF
strline= "
for each x in Rs. Fields
StrLine = strLine & X.value & Chr (9)
Next
MyFile.WriteLine strLine
Rs. MoveNext
Loop
End If
Rs. Close
Set rs = Nothing
Response.Write "Generate Excel File Success!" Download: <input type= "button" "value=" "click Download" "onclick=" JavaScript Tutorial: window.open (' Aspprogra.xls ') ">"
%>