Copy Code code 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 ">
<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>
<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 * 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> serial number </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 ' hides the data in the fifth, tested if the display is none of the data is not derived
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>