国产探花免费观看_亚洲丰满少妇自慰呻吟_97日韩有码在线_资源在线日韩欧美_一区二区精品毛片,辰东完美世界有声小说,欢乐颂第一季,yy玄幻小说排行榜完本

首頁 > 編程 > ASP > 正文

asp將table生成excel文件(xls)

2024-05-04 11:08:41
字體:
來源:轉載
供稿:網友
asp將table生成xls文件的實現代碼。
 
 
 
復制代碼代碼如下:

<%@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>無標題文檔</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="導出數據" onclick="tableToExcel()" /> 
<% 
ConnStr="..." 
Set conn = Server.CreateObject("ADODB.Connection") 
conn.Open connstr 

set rs = server.CreateObject("adodb.recordset") 
rs.open "select top 10 * from [你的表名]",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>序號</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 '在第五條的時候隱藏數據,經過測試如果是display為none的數據是不會導出來的 
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>

發表評論 共有條評論
用戶名: 密碼:
驗證碼: 匿名發表
主站蜘蛛池模板: 无极县| 政和县| 高密市| 慈溪市| 乐业县| 巴南区| 进贤县| 洮南市| 平阳县| 荆门市| 金川县| 肃宁县| 静安区| 永德县| 壤塘县| 青州市| 中阳县| 泾阳县| 凭祥市| 孝义市| 新蔡县| 柘荣县| 莎车县| 长阳| 岳阳市| 静安区| 鄄城县| 庆阳市| 涡阳县| 博白县| 随州市| 雷州市| 宁乡县| 长子县| 温州市| 白水县| 依兰县| 民勤县| 克东县| 黄浦区| 民县|