Home >Database >Mysql Tutorial >将excel中的数据批量导入到access的技巧

将excel中的数据批量导入到access的技巧

WBOY
WBOYOriginal
2016-06-07 15:15:471868browse

将excel中的 数据 批量 导入 到access % DB="db1.mdb" path=Server.MapPath(DB) set conn=server.createobject("adodb.Connection") connstr="provider=Microsoft.Jet.OLEDB.4.0;Data Source="path conn.Open connstr Set rs=server.CreateObject("adodb.rec

将excel中的数据批量导入到access

DB="db1.mdb"
path=Server.MapPath(DB)
set conn=server.createobject("adodb.Connection")
connstr="provider=Microsoft.Jet.OLEDB.4.0;Data Source="&path
conn.Open connstr
Set rs=server.CreateObject("adodb.recordset")

'===========================================
' 函数功能:数据批量导入
' 作    者:wangsdong
' 文章为作者原创,转载请注明文章出处、保留作
' 者信息,谢谢支持!
' 原理:将excel中的数据导入到access
'===========================================

'连接excel数据教程
path="./"
Dim xlsconn,strsource,xlbook,xlsheet,i
Dim myConn_Xsl,xlsrs,sql,objCmd  
Set xlsconn = server.CreateObject("adodb.connection")
Set xlsrs = Server.CreateObject("Adodb.RecordSet")

filename="商品" 
file2="商品列表"
source=server.mappath(path&filename&".xls")

myConn_Xsl="Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" &source& ";Extended Properties=Excel 8.0"
xlsconn.open myConn_Xsl

sql = "Select * from ["&file2&"$]"
xlsrs.open sql,xlsconn,1,1
If xlsrs.eof Then
else
 i=1
 response.write "

"
 Do While not xlsrs.eof
 goods_name=xlsrs("商品名")
 goods_images=xlsrs("图片")
 cat_id=xlsrs("商品分类")
 %>
 
 
  
    
   
 

   sql="insert into goods(goods_name,goods_images,cat_id) values('"&goods_name&"','"&goods_images&"',"&cat_id&")"
  conn.execute(sql)
 i=i+1
 xlsrs.MoveNext
    Loop 
 response.write "

    
"
End If
xlsrs.close

Response.write "共导入" & i-1 & "条记录.
" & vbCrLf

set xlsconn=nothing
set objCmd=nothing
%>

access 结构
goods_name,goods_images cat_id

excel结构
商品名,图片,商品分类

本地链接地址:http://www.j245.com/Class.asp?ID=111

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn