当前位置: 移动技术网 > IT编程>开发语言>.net > 用ASP将数据库中的数据直接导出到EXCEL表中

用ASP将数据库中的数据直接导出到EXCEL表中

2018年09月16日  | 移动技术网IT编程  | 我要评论

疯狂seo,异能狂想,皖2005j201

asp实例代码,直接将中的数据导出到excel电子表中。

<!--#include file="../conn."-->
<% 
 
dim s,sql,filename,fs,myfile,x 
 
set fs = server.createobject("scripting.filesystemobject") 
--假设你想让生成的excel文件做如下的存放 
filename = server.mappath("users.xls") 
--如果原来的excel文件存在的话删除它 
if fs.fileexists(filename) then 
    fs.deletefile(filename) 
end  if 
--创建excel文件 
set myfile = fs.createtextfile(filename,true) 
 
set rs = server.createobject("adodb.recordset") 
--从数据库中把你想放到excel中的数据查出来 
sql = "select * from tb_execl order by id desc" 
rs.open  sql,conn 
starttime = request("starttime")
endtime = request("endtime")
startendtime = "addtime between #"& starttime &" 00:00:00# and #"& endtime &" 23:59:59#"

strsql = "select * from myeky_myusr "
set rstdata =conn.execute(strsql)
if not rstdata.eof and not rstdata.bof then 
 
    dim  trline,responsestr 
    strline="" 
    for each x in rstdata.fields 
        strline = strline & x.name & chr(9) 
   next 
 
--将表的列名先写入excel 
    myfile.writeline strline 
 
    do while not rstdata.eof 
        strline="" 
 
        for each x in rstdata.fields 
            strline = strline & x.value &  chr(9) 
        next 
        myfile.writeline  strline 
 
        rstdata.movenext 
    loop 
 
end if 

response.write  "生成excel文件成功,点击<a href=""users.xls"" target=""_blank"">下载</a>!"

rstdata.close 
set rstdata = nothing
conn.close
set conn = nothing
%>

如对本文有疑问,请在下面进行留言讨论,广大热心网友会与你互动!! 点击进行留言回复

相关文章:

验证码:
移动技术网