如何将excel数据通过asp导入数据库

如何将excel数据通过asp导入数据库,第1张

将excel数据通过asp导入数据库:

参考代码:

wenjian=request.Form("floor")

fileext=mid(wenjian,InStrRev(wenjian,".")+1)

if lcase(fileext)<>"xls" then

response.write "<script>alert ('文件格式不对,请上传Excel文件')window.location.href='updateFloor.asp'</script>"

response.end

end if

set conne=server.CreateObject("ADODB.Connection")

connStre="Provider=Microsoft.Jet.OLEDB.4.0Data Source=" &Server.MapPath( ""&wenjian&"" )&"Extended Properties='Excel 8.0HDR=YESIMEX=1'"

conne.open connStre

Sqle="select * from [sheet1$] "

Set rse = Server.CreateObject("ADODB.Recordset")

rse.open sqle,conne,1,1

'验证

hang=2

do while not rse.eof

'名称不能为空

if trim(rse(0))<>"" then

else

mess="第"&hang &"行名称为空,请检查!"

response.Write"<script>alert('"&mess &"').window.location.href='updateFloor.asp'</script>"

response.End()

end if

rse.movenext

hang=hang+1

loop

rse.movefirst

do while not rse.eof

set rst=server.CreateObject("adodb.recordset")

sqlt="select * from Sellman"

rst.open sqlt,conn,1,3

rst.addnew()

rst("CompanyName")=c2(rse(0))

rst("CompanyInfo")=c2(rse(1))

rst("address")=c2(rse(2))

rst("tel")=c2(rse(3))&" "&c2(rse(7))

rst("Fax")=c2(rse(4))

rst("linkman")=c2(rse(5))

rst("Homepage")=c2(rse(8))

rst("Email")=c2(rse(6))

rst.update()

rst.close

set rst=nothing

rse.movenext

loop

rse.close

set rse=nothing

response.Write "<script>alert('导入成功!')location.href='updateFloor.asp'</script>"

链接函数:

sub conn_xls(connxls,dbpath)

Set connxls=Server.CreateObject("ADODB.Connection")

StrConn="Provider=Microsoft.Jet.OLEDB.4.0Extended Properties='excel 8.0hdr=yes'Data Source="&Server.MapPath(dbpath)

connxls.Open StrConn

end sub

使用方法

call conn_xls(connxls,"excel.xls")

这就链接成功了。

访问数据方式和ACCESS差不多。ASP有点基础就会 *** 作。


欢迎分享,转载请注明来源:内存溢出

原文地址:https://54852.com/sjk/6908940.html

(0)
打赏 微信扫一扫微信扫一扫 支付宝扫一扫支付宝扫一扫
上一篇 2023-03-30
下一篇2023-03-30

发表评论

登录后才能评论

评论列表(0条)

    保存