asp把execl导入access
来源:
互联网
日期:2012-7-31
Tc711Com提示:asp把execl导入access | <% Set xml=Server.CreateObject("Microsoft.XMLDOM") xml.Async=False xml.Load(Server.MapPath("MobileFlash.xml"))
Set rootNode=xml.documentElement FlashPath=rootNode.childNodes(0).text Set rootNode=Nothing Set xml=Nothing
Set xml=Server.CreateObject("Microsoft.XMLDOM") xml.Async=False xml.Load(Server.MapPath("MobileXls.xml"))
Set rootNode=xml.documentElement XlsPath=rootNode.childNodes(0).text Set rootNode=Nothing Set xml=Nothing
sub xlsmdb(xls) '这里用来写导入数据库的程序 kl=xls strAddr = Server.MapPath(XlsPath&kl)
Set adox = CreateObject("ADOX.Catalog") Set connXls = CreateObject("ADODB.Connection") connXls.open "Provider=Microsoft.Jet.OLEDB.4.0;Data Source="& strAddr &";Extended Properties=""Excel 8.0;HDR=Yes;IMEX=1""" adox.activeConnection = connXls for each table in adox.tables if table.type="TABLE" then
'开始导入表结构 op=table.name sqlxls="select * from "+"["+ op+"]" set rsxls=server.createobject("adodb.recordset") rsxls.open sqlxls,connXls,1,1 str="ID Counter" for i=0 to rsxls.Fields.Count-1 str=str&","&rsxls.fields(i).name&" string" next
sql="Create Table "& Replace(Replace(Replace(op,"$",""),",",""),"'","") &" (" & str & ")" set conn = Server.CreateObject("ADODB.Connection") DBPath = Server.MapPath("./database/Fangzhen.mdb") conn.Open "driver={Microsoft Access Driver (*.mdb)};dbq=" & DBPath
set rstSchema=conn.openSchema(20) rstSchema.movefirst Do Until rstSchema.EOF if rstSchema("TABLE_Name")=Replace(Replace(Replace(op,"$",""),",",""),"'","") then k=5 end if rstSchema.movenext Loop rsxls.close set rsxls=nothing if k<>5 then'避免重复导入
conn.execute(sql) '开始导入数据 Set rsxls=server.createobject("adodb.recordset") sqlxls="select * from ["& op &"]" rsxls.open sqlxls,connXls,1,1
Set rs=server.createobject("adodb.recordset") sql="select * from ["& Replace(Replace(Replace(op,"$",""),",",""),"'","") &"]" rs.open sql,conn,1,2 do while not rsxls.eof
rs.addnew
for i=0 to rsxls.fields.count-1 rs(i+1)=rsxls(i) i=i+1 next
rsxls.movenext loop rs.update rsxls.close rs.close
end if k=0'避免重复导入结束 '一个工作表导入完毕
end if next '导入完成 end sub %>
更多的asp把execl导入access请到论坛查看: http://BBS.TC711.COM
【 双击滚屏 】 【 评论 】 【 收藏 】 【 打印 】 【 关闭 】
来源:
互联网
日期:2012-7-31
|
|
|