当前位置:K88软件开发文章中心编程语言AspAsp01 → 文章内容

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

减小字体 增大字体 作者:佚名     来源:asp编程网  发布时间:2018-12-30 8:32:07

asp数据批量导入的原理是使用excel保存许多数据,然后将这个excel使用无组件上传到服务器上,然后打开excel,将里面的数据写入到数据库中。
无组件上传见:http://www.aspprogram.cn/html/soft/2008624191142.html
这里我写的是将excel中的数据读出来,然后写入到数据库中
具体代码:
<
!--
#include file="adoconn.asp" -->

<
%
'===========================================
' 函数功能:数据批量导入
' 作 
 
 
者:wangsdong
' 网 
 
 
站: http://www.aspprogram.cn
' 文章为作者支持!
' 原理:将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 "<
TABLE border=1>
"
 
Do While not xlsrs.eof
 
goods_name=xlsrs("商品名")
 
goods_images=xlsrs("图片")
 
cat_id=xlsrs("商品分类")
 
%>

 

 
<
TR>

 
 
<
TD>
&
nbsp
<
%=goods_name%>
<
/TD>

 
 
<
TD>
&
nbsp
<
%=goods_images%>
<
/TD>
 
 

 
 
<
TD>
&
nbsp
<
%=cat_id%>
<
/TD>
 

 
<
/TR>

 
<


 
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 "<
/table>
"
End If
xlsrs.close

Response.write "共导入<
font color='red'>
" &
i-1 &
"<
/font>
条记录.<
br>
" &
vbCrLf

set xlsconn=nothing
set objCmd=Nothing

% >


源码下载地址:
http://www.aspprogram.cn/html/soft/20081030113418.html

这里的图片要使用ftp上传到指定的目录images下面,这样就行



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