知识库

ASP将access数据导出为excel电子表的方法

来源: 本站    类别: 知识库    日期: 2010/6/7

 

      有一个客户要求后台生成大数据量(每次生成几万条)的会员卡号及密码,金额等。生成的会员卡号及密码要印制在卡上对会员发放。生成大量数据在库中,印制卡片的厂家要拿到数据进行印制怎么办呢?

      于是我想到用代码将access中的数据生成Excel表格导出。打印这样不就可以了吗?在网上查找相关资料可都不尽如我意,就自己动手写了这个程序。现放出来供大家分享!大家知道写代码很辛苦,所以要用或者转贴时一定注明出处:http://www.6yee.cn

下面为代码:

以下为引用的内容:

<!--#include file="../conn.asp"-->
<%
if session("china_admin")="" then response.redirect "login.asp"
dbpath="../"
dblink
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 china_car"
rs.Open session("sql"),conn,1,1
n=1

'==================================================================
'==============================================================建立excel文件系统
filename = Server.MapPath("car/CarTable"&n&".xls") '这个是为了方便,新建一个CAR的文件夹,这个可以自己设啦
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="序号|卡号|密码|积分数|金额"  '这个根据你的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("car/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="car/CarTable"&n&".xls"
response.Write "导出成功  "
response.write("<a href='" & server.URLEncode(ExcelPath) & "'><font=red>下载</font></a>")

%>


相关文章


Copyright © 2004 - 2024 CNHWW Inc. All Rights Reserved
石家庄市征红网络科技有限公司版权所有 邮政编码:050051
服务电话:0311-85315152 13931185013 在线客服QQ:81447932 / 81447933 邮箱: cnhww@163.com