asp将table生成excel文件(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
%>




无标题文档






<%
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("")
response.Write("")
for each f in rs.fields
response.Write("")
next
response.Write("")
for j = 1 to rs.recordcount
if j > 5 then '在第五条的时候隐藏数据,经过测试如果是display为none的数据是不会导出来的
response.Write("")
else
response.Write("")
end if
response.Write("")
for i = 0 to column - 1
response.Write("")
next
response.Write("")
rs.movenext
next
response.Write("
序号" & f.name & "
" & j & "" & rs(i) & "
")
end if
rs.close
set rs = nothing
conn.close
set conn = nothing
%>


你可能感兴趣的:(asp将table生成excel文件(xls))