打开Excel文件(测试过)

来源:互联网 发布:java语言特点 编辑:程序博客网 时间:2024/05/22 12:33
参考资料: http://wenwen.soso.com/z/q275114738.htm

在SQL2008 + Excel2003 下测试通过,代码如下:

--1、启用Ad Hoc Distributed Queriesexec sp_configure 'show advanced options',1reconfigureexec sp_configure 'Ad Hoc Distributed Queries',1reconfigure        Go--2、导入select * from OPENROWSET('MICROSOFT.JET.OLEDB.4.0','Excel 5.0;HDR=YES;DATABASE=D:\Tmp\abc\01.xls',sheet1$)        Go-- 3、关闭Ad Hoc Distributed Queriesexec sp_configure 'Ad Hoc Distributed Queries',0reconfigureexec sp_configure 'show advanced options',0reconfigure Go
 

在使用openrowset/opendatasource前首先要启用Ad Hoc Distributed Queries服务,因为这个服务不安全所以SqlServer默认是关闭的
0 0
原创粉丝点击