dim rs
set rs=server.createobject("adodb.recordset")
rs.Open "select * from table order by code",conn,1,3
dim i
i=1
str="<table width=100% border=1 cellspacing=0 cellpadding=0>"
str=str&chr(10)&"<tr> "
str=str&chr(10)&" <td height=25 colspan=6 align=center><strong>标题</strong></td>"
str=str&chr(10)&"</tr>"
str=str&chr(10)&" <tr align=center> "
str=str&chr(10)&"<td>序号</td>"
str=str&chr(10)&" <td>编号</td>"
str=str&chr(10)&" <td>名称</td>"
str=str&chr(10)&"<td>时间</td>"
str=str&chr(10)&"</tr>"
do while not rs.eof
str=str&chr(10)&"<tr>"
str=str&chr(10)&"<td>"&i&"</td>"
str=str&chr(10)&"<td>"&rs("code")&"</td>"
str=str&chr(10)&"<td>"&rs("name")&"</td>"
str=str&chr(10)&"<td>"&rs("time")&"</td>"
str=str&chr(10)&" </tr>"
i=i+1
end if
rs.movenext
loop
str=str&chr(10)&"</table>"
set fso=Server.CreateObject("Scripting.FileSystemObject")
set f = fso.CreateTextFile(Server.MapPath("导出excel.xls"),8,true)
f.writeline str
f.close
set f=nothing
set fso=nothing
%>
<a href="导出excel.xls" target="_blank">点击下载:导出excel.xls</a>
我做了 个比较容易理解的
<%
if session("user_name")="" then
response.Redirect url&"error.asp?msg=您这样的操作本系统令人感到耻辱!&logout=true"
end if
tempdata=trim(Request("strPhoto"))
sql = "SELECT * into temp FROM OpenDataSource( 'Microsoft.Jet.OLEDB.4.0','Data Source="&tempdata&";User ID=Admin;Password=;Extended properties=Excel 5.0')...[Sheet1$] "
conn.execute(sql)
sqlp = "select * from temp"
set rsp=server.createobject("adodb.recordset")
rsp.open sqlp,conn,1,1
i=0
do while not rsp.eof
sqlq = "select * from USER_VALIDATE where stu_no='"&rsp("stu_no")&"'"
set rsq=server.createobject("adodb.recordset")
rsq.open sqlq,conn,1,1
if rsq.eof then
sql = "insert into USER_VALIDATE (stu_no,stu_name,stu_class) values('"&rsp("stu_no")&"','"&rsp("stu_name")&"','"&rsp("stu_class")&"')"
conn.Execute(sql)
i=i+1
end if
rsq.close
rsp.movenext
loop
rsp.close
a=""
sql="delete from USER_VALIDATE where stu_no='"&a&"'"
conn.execute(sql)
sql="drop table temp"
conn.execute(sql)
conn.close
set conn = nothing