A customer requires the backend to generate a large amount of data (tens of thousands of items each time) of membership card numbers, passwords, amounts, etc. The generated membership card number and password must be printed on the card and issued to members. A large amount of data is generated in the database. What should the card printing manufacturer do if it wants to get the data for printing?
So I thought of using code to generate an Excel table and export the data in access. Isn’t it enough to just print it? Searching for relevant information on the Internet was not satisfactory, so I wrote this program myself. Now released for everyone to share!
The following is the code:
The following is the quoted content: <!--#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 '================================================== ================= '================================================== =============Create excel file system filename = Server.MapPath(car/CarTable&n&.xls) 'This is for convenience. Create a new CAR folder. You can set this yourself. if fs.FileExists(filename) then'If the file exists, overwrite it. fs.DeleteFile(filename) end if set myfile = fs.CreateTextFile(filename,true) '================================================== ======================= dim strLine,responsestr strLine= dim work,j,i str=serial number|card number|password|number of points|amount' This is set according to your access data table field. 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) 'You can set this yourself if fs.FileExists(filename) then'If the file exists, overwrite it. fs.DeleteFile(filename) end if set myfile = fs.CreateTextFile(filename,true) end if next myfile.writeline strLine rs.MoveNext loop rs.Close setrs=nothing conn.close set conn = nothing set myfile = nothing Set fs=Nothing ExcelPath=car/CarTable&n&.xls response.Write exported successfully response.write(<a href=' & server.URLEncode(ExcelPath) & '><font=red>Download</font></a>) %> |