itE-SPACE: normal; LETTER-SPACING: normal; COLOR: rgb(34,34,34); WORD-SPACING: 0px; PADDING-TOP: 0px; -webkit-text-stroke-width: 0px">有一個客戶要求后臺生成大數(shù)據(jù)量(每次生成幾萬條)的會員卡號及密碼,金額等。生成的會員卡號及密碼要印制在卡上對會員發(fā)放。生成大量數(shù)據(jù)在庫中,印制卡片的廠家要拿到數(shù)據(jù)進(jìn)行印制怎么辦呢?
于是我想到用代碼將access中的數(shù)據(jù)生成Excel表格導(dǎo)出。打印這樣不就可以了嗎?在網(wǎng)上查找相關(guān)資料可都不盡如我意,就自己動手寫了這個程序。現(xiàn)放出來供大家分享!
下面為代碼:
以下為引用的內(nèi)容:
<!–#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文件系統(tǒng)
filename = Server.MapPath("car/CarTable"&n&".xls") '這個是為了方便,新建一個CAR的文件夾,這個可以自己設(shè)啦
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="序號|卡號|密碼|積分?jǐn)?shù)|金額" '這個根據(jù)你的access數(shù)據(jù)表字段設(shè)置。
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") '這個可以自己設(shè)啦
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 "導(dǎo)出成功 "
response.write("<a href='" & server.URLEncode(ExcelPath) & "'><font=red>下載</font></a>")
%>
未經(jīng)允許不得轉(zhuǎn)載:445IT之家 » ASP將access數(shù)據(jù)導(dǎo)出為excel電子表的方法