将SQL数据导出到Excel插入指定的工作表

时间:2015-07-16 20:17:30

标签: sql-server-2008 excel-2010

最终我尝试从SQL表中导出数据并将其插入Excel工作表中的选项卡,然后将其邮寄给一个组。我不是100%设置这种做法的方法,但这是我在网上找到的唯一方法似乎表明它会得到我想要的东西,但遗憾的是我找不到针对这个特定问题的修复方法。但每次我尝试它时都会收到一个错误,暗示该文件是只读的。我检查了文件,我有权利,我也重新启动服务器,认为它可能锁定在内存中,但仍然没有。 我整天都在谷歌上搜索,并在这一点上达到了我的突破点。它是带有SQL Server 2008的Windows 2008 R2 Enterprise服务器。

EXEC sp_MSset_oledb_prop N'Microsoft.ACE.OLEDB.12.0', N'AllowInProcess', 1

EXEC sp_MSset_oledb_prop N'Microsoft.ACE.OLEDB.12.0', N'DynamicParameters', 1


 insert into OPENROWSET('Microsoft.ACE.OLEDB.12.0',
 'Excel 12.0;Database=D:\Template\Availability.xlsx;IMEX=1;HDR=YES','SELECT [Site ID],[Schedule Date] FROM [Quota_Points$A:J]') 
 Select [Site ID],[Schedule Date] from 
 (select [Site_ID] as 'Site ID'
      ,[Schedule_Date] AS 'Schedule Date'

       from [smb].[dbo].[JobAvailability]) a

错误讯息:

Error(s)
OLE DB provider "Microsoft.ACE.OLEDB.12.0" for linked server "(null)" returned message "Cannot update. Database or object is read-only.".
Msg 7399, Level 16, State 1, Line 1

The OLE DB provider "Microsoft.ACE.OLEDB.12.0" for linked server "(null)" reported an error. The provider indicates that the user did not have the permission to perform the operation.


Msg 7343, Level 16, State 2, Line 1
The OLE DB provider "Microsoft.ACE.OLEDB.12.0" for linked server "(null)" could not INSERT INTO table "[Microsoft.ACE.OLEDB.12.0]". 

0 个答案:

没有答案