<% @ Language = "VBScript" codePage = "936" %>
<%
If request ("action") = 1 then
Response. contenttype = "application/MS-excel"
Response. addheader "content-disposition", "attachment?filename=www.xls"
End if
%>
<! Doctype HTML public "-// W3C // dtd xhtml 1.0 transitional // en" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<HTML xmlns = "http://www.w3.org/1999/xhtml">
<Head>
<Meta http-equiv = "Content-Type" content = "text/html; charset = gb2312"/>
<Title> untitled document </title>
<Style type = "text/CSS">
Table {
Border-top: 1px solid #003399;
Border-left: 1px solid #003399;
}
TD {
Border-Right: 1px solid #003399;
Border-bottom: 1px solid #003399;
}
Thead {
Background-color: #000066;
Font-weight: bold;
Padding: 5px;
Color: # ffffff;
}
</Style>
<Script language = "JavaScript">
Function tabletoexcel (){
Location. href = '? Action = 1 ';
}
</SCRIPT>
</Head>
<Body>
<Input type = "button" value = "export data" onclick = "tabletoexcel ()"/>
<%
Connstr = "..."
Set conn = server. Createobject ("ADODB. Connection ")
Conn. Open connstr
Set rs = server. Createobject ("ADODB. recordset ")
Rs. Open "select top 10 * from [your table name]", Conn, 1, 1
If not (Rs. EOF and Rs. bof) then
Column = Rs. Fields. Count
Response. Write ("<Table cellpadding = '0' cellspacing = '0'> ")
Response. Write ("<thead> <TD> NO. </TD> ")
For each F in RS. Fields
Response. Write ("<TD>" & F. Name & "</TD> ")
Next
Response. Write ("</thead> ")
For j = 1 to Rs. recordcount
If j> 5 then': Hide the data in the fifth step. After testing, if the display is none, the data will not be exported.
Response. Write ("<tr style = 'display: none'> ")
Else
Response. Write ("<tr> ")
End if
Response. Write ("<TD>" & J & "</TD> ")
For I = 0 to column-1
Response. Write ("<TD>" & RS (I) & "</TD> ")
Next
Response. Write ("</tr> ")
Rs. movenext
Next
Response. Write ("</table> ")
End if
Rs. Close
Set rs = nothing
Conn. Close
Set conn = nothing
%>
</Body>
</Html>