sql2008_x64 读取excel

时间:2021-10-14 18:52:30

sql2008_x64 读取excel

下载64bit 版的AccessDatabaseEngine_x64:http://www.microsoft.com/en-us/download/details.aspx?id=13255

 --开启导入功能
exec sp_configure 'show advanced options',
reconfigure
exec sp_configure 'Ad Hoc Distributed Queries',
reconfigure
--允许在进程中使用ACE.OLEDB.
EXEC master.dbo.sp_MSset_oledb_prop N'Microsoft.ACE.OLEDB.12.0', N'AllowInProcess',
--允许动态参数
EXEC master.dbo.sp_MSset_oledb_prop N'Microsoft.ACE.OLEDB.12.0', N'DynamicParameters', --导入临时表
EXEC ('SELECT * FROM OPENROWSET(''Microsoft.ACE.OLEDB.12.0'', ''Excel 12.0;Database=D:\AGS-1249.xlsx;DHR=YES'', ''SELECT * FROM [Sheet1$]'')')
--select * from opendatasource('Microsoft.Ace.OLEDB.12.0','Data Source=D:/AGS-1249.xlsx;Extended properties=Excel 12.0;hdr=yes;IMEX=1')...[sheet1$]
--注意这里,要先关闭外围的设置,然后再关闭高级选项
exec sp_configure'Ad Hoc Distributed Queries',
reconfigure
exec sp_configure'show advanced options',
reconfigure
--关闭ACE.OLEDB.12的选项
EXEC master.dbo.sp_MSset_oledb_prop N'Microsoft.ACE.OLEDB.12.0', N'AllowInProcess',
EXEC master.dbo.sp_MSset_oledb_prop N'Microsoft.ACE.OLEDB.12.0', N'DynamicParameters',