当前位置: 首页 > 图文教程 > 网络编程 > ASP > asp将table生成excel文件(xls)

ASP
对ASP和ASP程序员的一些话
10行代码让你告别Arp作恶导致的掉线
ASP开发10条经验总结
国内ASP应用,不容乐观
ASP利用Google实现在线翻译功能
如何提高自己的编程水平
经典实用的基础asp程序整理
ASP实现带进度条的测试网速的代码程序
ASP程序实现网页伪静态页源代码
净化网络环境 ASP程序实现过滤脏话
ASP技术与PHP,CGI,JSP等技术的比较
用ASP制作饼图、柱状图等
常用ASP脚本程序集锦
用ASP编写的俄罗斯方块游戏
几种优秀的开发ASP的工具
浅谈ASP编程的思路与纠错
一个测试数据库连接的函数
ASP读写注册表
怎样用ASP程序判断一个盘上是否有文件
一个免费的简单聊天室源代码

ASP 中的 asp将table生成excel文件(xls)


出处:互联网   整理: 软晨网(RuanChen.com)   发布: 2010-01-10   浏览: 72 ::
收藏到网摘: n/a

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>