ASP导出为EXCEL文件
浏览:3753 类型:程序语言 发布人:mykame 发布日期:2012/3/15 14:50:19
<%
dbpath="../../data/sto/"
dim filename,fs,myfile,x,m,n,o,link
Set fs = server.CreateObject("scripting.filesystemobject")
Set rs = Server.CreateObject("ADODB.Recordset")
session("sql") = "SELECT * FROM (SELECT DISTINCT bbx_materiel_size.MSEsize, bbx_stock.BSName, bbx_materiel_category.MCYID, bbx_materiel_brand.MBDbrand, bbx_materiel_model.MMLmodel, bbx_materiel_color.MCRcolor, bbx_stock.BSAmount, bbx_materiel_size.MSEsale, bbx_stock.BSState, bbx_materiel_category.MCYName, bbx_stock.BSDpdm FROM bbx_stock INNER JOIN (bbx_materiel_size INNER JOIN (((bbx_materiel_color INNER JOIN bbx_materiel_model ON bbx_materiel_color.MCRfather = bbx_materiel_model.MMLID) INNER JOIN bbx_materiel_brand ON bbx_materiel_model.MMLfather = bbx_materiel_brand.MBDID) INNER JOIN bbx_materiel_category ON bbx_materiel_brand.MBDfather = bbx_materiel_category.MCYID) ON bbx_materiel_size.MSEfather = bbx_materiel_color.MCRID) ON bbx_stock.BSName = bbx_materiel_size.MSEID WHERE (((bbx_materiel_category.MCYID)=1) AND ((bbx_stock.BSAmount)<>0) AND ((bbx_stock.BSDpdm)='SXM001')) ORDER BY bbx_materiel_category.MCYID, bbx_materiel_brand.MBDbrand, bbx_materiel_model.MMLmodel, bbx_materiel_color.MCRcolor, bbx_materiel_size.MSEsize) AS bass WHERE (((bass.MBDbrand) Like '%巴%') AND ((bass.MMLmodel) Like '%207%') AND ((bass.MCRcolor) Like '%黑%') AND ((bass.MSEsize) Like '%26%'));"
rs.Open session("sql"),conn,1,1
n=1
'==================================================================
'==============================================================建立excel文件系统
filename = Server.MapPath(dbpath&"CarTable"&n&".xls")
if fs.FileExists(filename) then'如果文件存在,覆盖它。
fs.DeleteFile(filename)
end if
set myfile = fs.CreateTextFile(filename,true)
'========================================================================
dim strLine,responsestr
strLine=""
dim work,j,i
str="MSEsize|BSName|MCYID|MBDbrand|MMLmodel|MCRcolor|BSAmount|MSEsale|BSState|MCYName|BSDpdm" '这个根据你的access数据表字段设置
work=split(str,"|")
j=ubound(work)
i=0
o=0
do while not i>j
strLine= strLine & work(i) & chr(9)
i=i+1
loop
myfile.writeline strLine
Do while Not rs.EOF
o=o+1
m=20000
strLine=""
for each x in rs.Fields
strLine= strLine & x.value & chr(9)
if o>=m*n then
n=n+1
filename = Server.MapPath("CarTable"&n&".xls") '这个可以自己设啦
if fs.FileExists(filename) then'如果文件存在,覆盖它。
fs.DeleteFile(filename)
end if
set myfile = fs.CreateTextFile(filename,true)
end if
next
myfile.writeline strLine
rs.MoveNext
loop
rs.Close
set rs = nothing
conn.close
set conn = nothing
set myfile = nothing
Set fs=Nothing
ExcelPath="CarTable"&n&".xls"
response.Write "导出成功 "
response.write("<a href='" & server.URLEncode(dbpath&ExcelPath) & "'><font=red>下载</font></a>")
%>
上一篇:javascript加入收藏|设为首页|联系我们 下一篇:TEXTAREA自适应文字行数的多少
其它相关文章
您没有ASPEncodeDLL.AspCoding 对象的操作权限或该对象不存在,请联系服务器管理员 解决方法
sql server “不允许保存更改,您所做的更改要求删除并重新创建以下表”错误的解决办法
WIN2003 IIS6 Request 对象 错误 'ASP 0104 : 80004005' 不允许操作|IIS6取消限制上传超200KB文件方法