asp 导入execl
发布网友
发布时间:2022-08-15 04:30
我来回答
共2个回答
热心网友
时间:2023-09-12 06:23
<%
dim conn
dim connstr
on error resume next
connstr="DBQ="+server.mappath("../MBData/Mb.mdb")+";DefaultDir=;DRIVER={Microsoft Access Driver (*.mdb)};"
set conn=server.createobject("ADODB.CONNECTION")
if err then
err.clear
else
conn.open connstr
end if
dim excelstring
dim excelstr
dim excelstr2
dim head
dim sql
aa="http://"
sql=trim(request.QueryString("sql"))
excelstring = ""
head = "Ip" & "," & "地址" & "," & "语言" & "," & "来路" & "," & "访问页面" & "," & "时区" & "," & "系统" & "," & "浏览器" & "," & "屏幕尺寸" & "," & "屏幕颜色" & "," & "时间" & "," & "时间"
Set Rs = Server.CreateObject ("ADODB.Recordset")
Rs.open sql,conn,1,3
do while not Rs.eof
excelstr = Rs(0) &","& Rs(1) &","& Rs(2) &","& aa&split(Rs(3),"/")(2) &","& Rs(4) &","& Rs(5) &","& Rs(6) &","& Rs(7) &","& Rs(8) &","& Rs(9) &","& Rs(10) &","& Rs(11)
excelstr2 = excelstr2 & Chr(13) & excelstr
Rs.movenext
loop
excelstring = head & excelstr2
'response.Write(excelstring)
Rs.close
ufp=year(now)&month(now)&day(now)&hour(now)&minute(now)&second(now)
set fs = CreateObject("scripting.FileSystemObject")
set exc = fs.OpenTextFile(server.MapPath(ufp&".csv"),2,True)
exc.write(excelstring)
if fs.FileExists(Server.MapPath(ufp&".csv")) then
Response.Redirect(ufp&".csv")
'Response.write(excelstring)
else
Response.Write("导出文件失败!")
end if
%>
然后你在自己根据数据库的情况改一下,。
记得要加分哦。不懂的可以留言给我
head = "Ip" & "," & "地址" & "," & "语言" & "," & "来路" & "," & "访问页面" & "," & "时区" & "," & "系统" & "," & "浏览器" & "," & "屏幕尺寸" & "," & "屏幕颜色" & "," & "时间" & "," & "时间"
这段是标题。。就是导入EXECL的第一行
excelstr = Rs(0) &","& Rs(1) &","& Rs(2) &","& aa&split(Rs(3),"/")(2) &","& Rs(4) &","& Rs(5) &","& Rs(6) &","& Rs(7) &","& Rs(8) &","& Rs(9) &","& Rs(10) &","& Rs(11)
这个是对应的字段。。。。就是导入EXECL列的值。
热心网友
时间:2023-09-12 06:24
这个不是简单的问题,可以说很复杂,也不是在这里说得清的。
建议去百度搜索一下类似下面的关键字:
ASP读取EXCEL文件
ASP如何一行一行的读取EXCEL数据库内容
ASP如何将EXCEL数据导入ACCESS(MS SQL)
。。。
等等。