本帖最后由 伏地魔 于 2024-3-6 18:26 编辑
我是一个ASP半调子爱好者,自己做了个程序想实现条件查询后的下载,试了好多次都没实现!请大神帮着给看看,谢谢!
【页面1】
查询条件输入页面,通过FORM方式获取time1、time2、time3、time4的值(页面截图如下)
【页面2】
以下为【页面2】的原代码
- <!--#include file="conn.asp"-->
- <%
- time1=request("time1")
- time2=request("time2")
- time3=request("time3")
- time4=request("time4")
- dim filename,fs,myfile,s,x
- Set fs = server.CreateObject("scripting.filesystemobject")
- '--假设你想让生成的EXCEL文件做如下的存放
- filename = Server.MapPath("download.xls")
- '--如果原来的EXCEL文件存在的话删除它
- if fs.FileExists(filename) then
- fs.DeleteFile(filename)
- end if
- '--创建EXCEL文件
- set myfile = fs.CreateTextFile(filename,true)
- if time1<>"" and time2<>"" then
- sql = "SELECT * FROM sp WHERE time>=#"&time1&" 00:00:00# and time<=#"&time2&" 23:59:59# order by id desc"
- else
- if time3<>"" and time4<>"" then
- sql = "SELECT * FROM sp WHERE exittime>=#"&time3&" 00:00:00# and exittime<=#"&time4&" 23:59:59# order by id desc"
- else
- sql = "select * from sp order by gdbj asc, id desc"
- end if
- end if
- Set rs=server.createobject("adodb.recordset")
- rs.open sql,db,3,1
- if not rs.EOF and not rs.BOF then
- dim trLine,responsestr
- strLine="序号"&chr(9)&"受理工号"&chr(9)&"用户名"&chr(9)&"办理号"&chr(9)&"联系号"&chr(9)&"是否弹窗"&chr(9)&"分类1"&chr(9)&"分类2"&chr(9)&"用户需求"&chr(9)&"登记时间"&chr(9)&"处理结果"&chr(9)&"处理人"&chr(9)&"处理备注"&chr(9)&"处理时间"
- '--将表的列名先写入EXCEL
- myfile.writeline strLine
- Do while Not rs.EOF
- strLine=id&chr(9)&tijiaogonghao&chr(9)&yonghuming&chr(9)&guzhanghao&chr(9)&lianxidianhua&chr(9)&sp&chr(9)&sp1&chr(9)&sp2&chr(9)&beizhu&chr(9)&time&chr(9)&chuli&chr(9)&exitname&chr(9)&exitbeizhu&chr(9)&exittime
- myfile.writeline strLine
- rs.MoveNext
- loop
- end if
- response.redirect "download.xls"
- link="<A HREF="&filename&"><font color=red><b>导出excel文件</b></font></a>"
- Response.write link
- rs.Close
- set rs = nothing
- '返回【页面1】
- response.write("window.top.location.href='download.asp';")
- %>
复制代码 |