ASP+ACCESS管理后台客户信息导出EXCEL的功能
答案:3 悬赏:60 手机版
解决时间 2021-03-20 11:30
- 提问者网友:戎马万世
- 2021-03-19 19:37
我想在管理后台添加一个可以导出客户信息的功能,请高手帮忙!完成后再追加分数!请加我的QQ276795381
最佳答案
- 五星知识达人网友:千夜
- 2021-03-19 21:06
<p><%response.contenttype = "application/vnd.ms-excel"%><br>在页面的开头,加上这一行就可以了,这是指出输出类型为excel</p> <p> </p> <p>也可以参考以下代码:</p> <p><!--#include file="../conn.asp"--><br><%<br>if session("china_admin")="" then response.redirect "login.asp"<br>dbpath="../"<br>dblink<br>dim filename,fs,myfile,x,m,n,o,link<br>set fs = server.createobject("scripting.filesystemobject")</p> <p>set rs = server.createobject("adodb.recordset")<br>session("sql") = "select * from china_car"<br>rs.open session("sql"),conn,1,1<br>n=1</p> <p>'==================================================================<br>'==============================================================建立excel文件系统<br>filename = server.mappath("car/cartable"&n&".xls") '这个是为了方便,新建一个car的文件夹,这个可以自己设啦<br>if fs.fileexists(filename) then'如果文件存在,覆盖它。<br>fs.deletefile(filename)<br>end if<br>set myfile = fs.createtextfile(filename,true)</p> <p>'========================================================================</p> <p>dim strline,responsestr<br>strline=""</p> <p>dim work,j,i<br>str="序号|卡号|密码|积分数|金额" '这个根据你的access数据表字段设置。<br>work=split(str,"|")<br>j=ubound(work)<br>i=0<br>o=0<br>do while not i>j<br>strline= strline & work(i) & chr(9) <br>i=i+1<br>loop</p> <p>myfile.writeline strline<br>do while not rs.eof<br>o=o+1<br>m=20000</p> <p><br>strline=""</p> <p>for each x in rs.fields<br>strline= strline & x.value & chr(9)<br>if o>=m*n then<br>n=n+1<br>filename = server.mappath("car/cartable"&n&".xls") '这个可以自己设啦<br>if fs.fileexists(filename) then'如果文件存在,覆盖它。<br>fs.deletefile(filename)<br>end if<br>set myfile = fs.createtextfile(filename,true)<br>end if<br>next</p> <p>myfile.writeline strline</p> <p>rs.movenext<br>loop</p> <p>rs.close<br>set rs = nothing<br>conn.close<br>set conn = nothing<br>set myfile = nothing<br>set fs=nothing<br>excelpath="car/cartable"&n&".xls"<br>response.write "导出成功 "<br>response.write("<a href='" & server.urlencode(excelpath) & "'><font=red>下载</font></a>")</p> <p>%></p> <p>引用自: <a href="http://wenwen.soso.com/z/urlalertpage.e?sp=shttp%3a%2f%2fwww.6yee.cn" target="_blank">http://www.6yee.cn</a></p>
全部回答
- 1楼网友:酒者煙囻
- 2021-03-19 23:44
<%@LANGUAGE="VBSCRIPT" CODEPAGE="65001"%>
<%
dim conn,strconn
strconn="driver={Microsoft Access driver (*.mdb)};dbq="&server.mappath("dataBase/DB#addressList.mdb")
set conn=server.CreateObject("adodb.connection")
conn.Open strconn
dim s,sql,filename,fs,myfile,x
Set fs = server.CreateObject("scripting.filesystemobject")
'--假设你想让生成的EXCEL文件做如下的存放
filename = Server.MapPath("excel.xls")
'--如果原来的EXCEL文件存在的话删除它
if fs.FileExists(filename) then
fs.DeleteFile(filename)
end if
'--创建EXCEL文件
set myfile = fs.CreateTextFile(filename,true)
StartTime = Request("StartTime")
EndTime = Request("EndTime")
StartEndTime = "AddTime between #"& StartTime &" 00:00:00# and #"& EndTime &" 23:59:59#"
strSql = "select * from tAddressList"
Set rstData = DataToRsStatic(conn,strSql)
if not rstData.EOF and not rstData.BOF then
dim trLine,responsestr
strLine = "序 号" & chr(9) & "姓 名" & chr(9) & "电 话" & chr(9) & "Q Q" & chr(9) & "邮 箱" & chr(9) & "地 址" & chr(9) & "生 日" & chr(9) & "备 注"
'--将表的列名先写入EXCEL
objSpreadsheet.Range("A1:F1").merge '合并单元格(单元区域)
myfile.writeline strLine
Do while Not rstData.EOF
strLine=""
strLine = rstData("fid") & chr(9) & rstData("fName")& chr(9) & rstData("fTel") & chr(9) & rstData("fQQ") & chr(9) & rstData("fEmail")& chr(9)&rstData("fAddress")& chr(9) &rstData("birthday")& chr(9) & rstData("fNote") & chr(9)& IfSendStr
myfile.writeline strLine
rstData.MoveNext
loop
end if
Response.Charset="utf-8"
Response.Write "<br><br>生成EXCEL文件成功,点击<a href=""excel.xls"" target=""_blank"">下载</a>!"
rstData.Close
set rstData = nothing
Conn.Close
Set Conn = nothing
Function DataToRsStatic(Conn,strSql)
Dim RsStatic
Set DataToRsStatic = Nothing
If Conn Is Nothing Then
Exit Function
End If
Set RsStatic = CreateObject("ADODB.RecordSet")
RsStatic.CursorLocation = 3
RsStatic.Open strSql,Conn,3,3
If Err.Number <> 0 Then
Exit Function
End If
Set DataToRsStatic = RsStatic
End Function
%>
- 2楼网友:底特律间谍
- 2021-03-19 22:43
正好我做过这个,分两步,先在根目录生成文件,再下载,步骤:<br>在客户列表信息的最上面添加2个链接<a href="?act=creatxls">EXCEL</a>,<a href="../order.xls">下载文件</a>,本页最上面添加代码<br><%<br>if request.QueryString("act")="creatxls" then<br>Set fso = server.CreateObject("scripting.filesystemobject") <br>filename = Server.MapPath("../order.xls") <br>if fso.FileExists(filename) then <br>fso.DeleteFile(filename) <br>end if <br>'--创建文件 <br>set myfile = fso.CreateTextFile(filename,true) <br><br>Set rs = Server.CreateObject("ADODB.Recordset") <br>sql = "select * from [order]" <br>rs.Open sql,conn,1,1 <br>if rs.EOF and rs.BOF then <br>response.write "无数据" <br>else <br>dim strLine,responsestr <br>strLine="" <br>'--将表的列名先写入<br>For each x in rs.fields <br>strLine = strLine & x.name & chr(9) <br>Next <br>myfile.writeline strLine <br>Do while Not rs.EOF <br>strLine="" <br>for each x in rs.Fields <br>strLine = strLine & x.value & chr(9) <br>next <br>'--将表的数据写入<br>myfile.writeline strLine <br>rs.MoveNext <br>loop <br>end if <br>rs.Close <br>set rs = nothing <br>Response.ContentType="application/x-msdownload" <br>response.write("<Script language='JavaScript'> alert('生成成功!');</Script>")<br>response.write("<meta http-equiv=refresh content=0;URL='orderlist.asp'>")<br>response.End<br>end if%><br>实际案例,肯定能用,分数给我吧
我要举报
如以上回答内容为低俗、色情、不良、暴力、侵权、涉及违法等信息,可以点下面链接进行举报!
点此我要举报以上问答信息
大家都在看
推荐资讯