asp实现excel中的数据导入数据库
<% Response.CodePage=65001%> <% Response.Charset="UTF-8" %> <% wenjian = request.Form("select") '获取文件扩展名 ext = FileExec(wenjian) '判断文件扩展名 if ext <> "xls" then response.Write("<script>alert('文件类型不对,请核实!');window.location.href='index.html';</script>") response.End() end if Dim objConn,objRS Dim strConn,strSql set objConn=Server.CreateObject("ADODB.Connection") set objRS=Server.CreateObject("ADODB.Recordset") excelFile = server.mappath(wenjian) '针对excel 2007 strConn = "Provider=Microsoft.ACE.OLEDB.12.0; Data Source=" & excelFile & ";" & "Extended Properties=Excel 8.0;" objConn.Open strConn strSql="SELECT * FROM [Sheet1$]" objRS.Open strSql,objConn,1,1 objRS.MoveFirst %><!--#include file="conn.asp"--><% '循环excel中所有记录 while not objRS.eof set rs = Server.CreateObject("Adodb.Recordset") '查询语句 sql_s = "select * from ceshi where lname='" & objRS(0) & "' and old='" & objRS(1) & "' and sex='" & objRS(2) & "' and guojia='" & objRS(3) & "' and QQ='" & objRS(4) & "'" rs.open sql_s, conn, 1, 1 '重复的数据不做录入操作 if rs.eof then '插入语句 '****excel中第一条不会被录入**** sql = "insert into ceshi (lname, old, sex, guojia, QQ)values ('" & objRS(0) & "', '" & objRS(1) & "', '" & objRS(2) & "', '" & objRS(3) & "', '" & objRS(4) & "')" '执行插入 conn.execute(sql) end if objRS.MoveNext rs.close set rs = nothing wend '又到了各种关闭的时候 conn.close set conn = nothing objRS.Close objConn.Close set objRS = Nothing set objConn = Nothing response.Write("<script>alert('导入成功');window.location.href='index.html';</script>") response.End() Function FileExec(fileName) FileExec = Mid(fileName,Instr(fileName,".")+1,Len(fileName)-Instr(fileName,".")) End Function %>
再分享一个简化版的代码
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.0;Data Source=" & Server.MapPath( ""&wenjian&"" )&";Extended Properties='Excel 8.0;HDR=YES;IMEX=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>"
其实简单的说象access 数据库一样,把excel文件打开,再进行读再写到access中你要写到sqlserver中就把写的过程改一下就成了
看下代码:
dim conn dim conn2 set conn=CreateObject("ADODB.Connection") conn.Open "Provider=Microsoft.Jet.OLEDB.4.0;Jet OLEDB:Database Password=;Data Source=c:\book1.mdb" set conn2=CreateObject("ADODB.Connection") conn2.Open "Provider=Microsoft.Jet.OLEDB.4.0;Jet OLEDB:Database Password=;Extended properties=Excel 5.0;Data Source=c:\book1.xls" sql = "SELECT * FROM [Sheet1$]" set rs = conn2.execute(sql) while not rs.eof sql = "insert into xxx([a],[b],[c],[d]) values('"& fixsql(rs(0)) &"','"& fixsql(rs(1)) &"','"& fixsql(rs(2)) &"','"& fixsql(rs(3)) &"')" conn.execute(sql) rs.movenext wend conn.close set conn = nothing conn2.close set conn2 = nothing function fixsql(str) dim newstr newstr = str if isnull(newstr) then newstr = "" else newstr = replace(newstr,"'","''") end if fixsql = newstr end function
免责声明:本站文章均来自网站采集或用户投稿,网站不提供任何软件下载或自行开发的软件!
如有用户或公司发现本站内容信息存在侵权行为,请邮件告知! 858582#qq.com
白云城资源网 Copyright www.dyhadc.com
暂无“asp实现excel中的数据导入数据库”评论...
《魔兽世界》大逃杀!60人新游玩模式《强袭风暴》3月21日上线
暴雪近日发布了《魔兽世界》10.2.6 更新内容,新游玩模式《强袭风暴》即将于3月21 日在亚服上线,届时玩家将前往阿拉希高地展开一场 60 人大逃杀对战。
艾泽拉斯的冒险者已经征服了艾泽拉斯的大地及遥远的彼岸。他们在对抗世界上最致命的敌人时展现出过人的手腕,并且成功阻止终结宇宙等级的威胁。当他们在为即将于《魔兽世界》资料片《地心之战》中来袭的萨拉塔斯势力做战斗准备时,他们还需要在熟悉的阿拉希高地面对一个全新的敌人──那就是彼此。在《巨龙崛起》10.2.6 更新的《强袭风暴》中,玩家将会进入一个全新的海盗主题大逃杀式限时活动,其中包含极高的风险和史诗级的奖励。
《强袭风暴》不是普通的战场,作为一个独立于主游戏之外的活动,玩家可以用大逃杀的风格来体验《魔兽世界》,不分职业、不分装备(除了你在赛局中捡到的),光是技巧和战略的强弱之分就能决定出谁才是能坚持到最后的赢家。本次活动将会开放单人和双人模式,玩家在加入海盗主题的预赛大厅区域前,可以从强袭风暴角色画面新增好友。游玩游戏将可以累计名望轨迹,《巨龙崛起》和《魔兽世界:巫妖王之怒 经典版》的玩家都可以获得奖励。
更新日志
2025年07月06日
2025年07月06日
- 小骆驼-《草原狼2(蓝光CD)》[原抓WAV+CUE]
- 群星《欢迎来到我身边 电影原声专辑》[320K/MP3][105.02MB]
- 群星《欢迎来到我身边 电影原声专辑》[FLAC/分轨][480.9MB]
- 雷婷《梦里蓝天HQⅡ》 2023头版限量编号低速原抓[WAV+CUE][463M]
- 群星《2024好听新歌42》AI调整音效【WAV分轨】
- 王思雨-《思念陪着鸿雁飞》WAV
- 王思雨《喜马拉雅HQ》头版限量编号[WAV+CUE]
- 李健《无时无刻》[WAV+CUE][590M]
- 陈奕迅《酝酿》[WAV分轨][502M]
- 卓依婷《化蝶》2CD[WAV+CUE][1.1G]
- 群星《吉他王(黑胶CD)》[WAV+CUE]
- 齐秦《穿乐(穿越)》[WAV+CUE]
- 发烧珍品《数位CD音响测试-动向效果(九)》【WAV+CUE】
- 邝美云《邝美云精装歌集》[DSF][1.6G]
- 吕方《爱一回伤一回》[WAV+CUE][454M]