asp 导出excel

asp 导出excel,第1张

Response.Buffer = True

Response.ContentType = "application/vnd.ms-excel"

Response.AddHeader "content-disposition","inlinefilename = SAR_List("&fid&"歼盯_"&rid&").xls"

我是用这羡脊种方式保兄改渗存为excel的,可以直接打开

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>")

%>


欢迎分享,转载请注明来源:内存溢出

原文地址: http://outofmemory.cn/tougao/12197378.html

(0)
打赏 微信扫一扫 微信扫一扫 支付宝扫一扫 支付宝扫一扫
上一篇 2023-05-21
下一篇 2023-05-21

发表评论

登录后才能评论

评论列表(0条)

保存