Copy codeThe Code is as follows: <% @ 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>