请教ASP高手·· 可以实现一个在线考试系统的· 试题导出功能,具体的例子,,,,

2024-12-22 14:14:33
推荐回答(1个)
回答1:

试题必须是数据库中的数据;
思想: 直接按照条件FSO生成一个 xls 文件, 生成完毕后显示下载地址,或者直接跳转到文件所在路径,下载 xls 文件;



导出文件如下:
<%
dim tj2,tj3,tj4,tj5,filename

if Trim(request("PID")) <> "" then
tj2="and PID = '"&Trim(request("PID"))&"'"
else
tj2=""
end if

if Trim(request("send")) <> "" then
tj3="and Delivery = '"&Trim(request("send"))&"'"
else
tj3=""
end if

if Trim(request("Print")) <> "" then
tj4="and Print = "&Cint(request("Print"))&""
else
tj4=""
end if

if Trim(request("Lock")) <> "" then
tj5="and Lock = '"&Trim(request("Lock"))&"'"
else
tj5=""
end if

Set rs = Server.CreateObject("ADODB.RecordSet")
sqlstr = "select HK,PID,Delivery,UserName,OrderID,Tel,Mobile,Amount,CMoney,Zip,Addr,Info from [Order] where 1=1 "&tj2&" "&tj3&" "&tj4&" "&tj5&" order by id desc"
rs.open sqlstr,conn,1,3
Set fs = server.CreateObject("scripting.filesystemobject")
'--假设你想让生成的EXCEL文件做如下的存放
filename= Year(Now)&Month(Now)&Day(Now)&".xls"
temp = filename
filename=server.mappath("/bak/"&filename)
'--如果原来的EXCEL文件存在的话删除它
if fs.FileExists(filename) then
fs.DeleteFile(filename)
end if
'--创建EXCEL文件
set myfile = fs.CreateTextFile(filename,true)
dim strLine,responsestr
strLine="" & "是否回款" & chr(9) & "产品" & chr(9) & "快递公司" & chr(9) & "收货人" & chr(9) & "快递单号" & chr(9) & "收件人电话" & chr(9) & "收件人手机" & chr(9) & "套数" & chr(9) & "代收款" & chr(9) & "邮编" & chr(9) & "收货地址" & chr(9) & "备注" & chr(9)
For each x in rs.fields
strLine= strLine & x.name & chr(9)
Next
'--将表的列名先写入EXCEL
myfile.writeline strLine
while not rs.eof
strLine=""
for each x in rs.Fields
strLine= strLine & x.value & chr(9)
next
'--将表的数据写入EXCEL
myfile.writeline strLine
rs.movenext
wend
link="请点击下载excel文件"
'Response.write link
response.redirect("/bak/"&temp)
set myfile = nothing
Set fs=Nothing
rs.close
%>

方法二就是有固模板,生成其他格式文件