Response.ContentType = "application/vnd.ms-excel"
Response.AddHeader "content-disposition","inlinefilename = SAR_List("&fid&"歼盯_"&rid&").xls"
set conn2=CreateObject("ADODB.Connection") '使用oledb方式和Excel的连接
conn2.Open "配滚Provider=Microsoft.Jet.OLEDB.4.0Jet OLEDB:Database Password=Extended properties=Excel 5.0Data Source="闷吵&FilePath
sql = "SELECT * FROM [excels$]"
set rs = conn2.execute(sql)
_________________________________
Extended properties=Excel 5.0这里应该可以设置为更高,7.0以上吧,但培罩余是5.0应该可以达到目的了
下面是读取一个EXCEL文件并将其写入数据备敏库的代码实例,亲测通过:注意:EXCEL里面的列名称要和数仿迟枝据库里的字段相同
<%
i=0
Dim cn,oConn,connstr
'打开XLS.
Set cn = Server.CreateObject("ADODB.Connection")
cn.Provider = "Microsoft.Jet.OLEDB.4.0 "
cn.ConnectionString = "Data Source=" &Server.MapPath("list.xls") &"" &_
"Extended Properties=Excel 8.0"
cn.Open
'打开MDB.
connstr="DBQ="+server.MapPath("TEST.mdb")+"DefaultDir=DRIVER={Microsoft Access Driver (*.mdb)}"
set oConn=server.CreateObject("ADODB.CONNECTION")
oConn.open connstr
'读取数据.
set rsRead=server.CreateObject("ADODB.Recordset")
rsRead.Open "select * from [list$]",cn,1,1
do until rsRead.EOF
'写入数据库.
oConn.Execute("Insert into eer(mc)Values('"&rsRead.Fields("mc"旦启) &"')" )
rsRead.MoveNext
i=i+1
loop
response.write("<p align=center>成功导入"&i&"条数据</p><br>")
response.Write("<p align=center><a href=javascript:window.close()>关闭窗口</a></p>")
%>
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)