Generate an Excel file for the specified record

Source: Internet
Author: User
Tags chr

<%
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>
&LT;TD width= "5%" height= "align=" "Center" ><input type= "checkbox" name= "checkbox" value= "checkbox" onclick= " Checkall (' id ') ' ></TD>
&LT;TD height= "align=" "Center" > Username </TD>
&LT;TD height= align= "center" > Password </TD>
&LT;TD width= "40%" height= "align=" "Center" > Content </TD>
&LT;TD align= "center" > Gender </TD>
&LT;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>
&LT;TD height= "align=" center "><input type=" checkbox "Name=" id "value=" <%=id%> "></TD>
&LT;TD height= "><%=username%></TD>"
&LT;TD height= "><%=password%></TD>"
&LT;TD height= "><%=content%></TD>"
&LT;TD height= align= "center" ><%=sex%></TD>
&LT;TD height= "align=" "left" >&nbsp;<%=ytime%></TD>
</TR>
<%
' ****************** above is the ****************** you want to show '
Rs.movenext
Loop
End If
Rs.close
%>

<TR>
&LT;TD height= "colspan=" 6 ">&nbsp;
<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 ') ">"
%>

Contact Us

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.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.