For dem, der bruger SQL SERVER 2012+, kan du bruge Microsoft OLEDB 12.0-udbyderen, der følger med SQL Server 2012+, og som giver dig mulighed for at bruge Excel 2007-2013 xlsx-filer til adhoc-distribuerede forespørgsler eller som en linket server. Eksempler nedenfor.
Excel-projektmappen 'Application.xlsx' har 3 arbejdsark Application, Device, UserFirst Activate Ad Hoc Queries på serveren.
USE MSDB
GO
sp_configure 'show advanced options', 1
GO
RECONFIGURE WITH OverRide
GO
sp_configure 'Ad Hoc Distributed Queries', 1
GO
RECONFIGURE WITH OverRide
GO
EXEC master . dbo. sp_MSset_oledb_prop N'Microsoft.ACE.OLEDB.12.0' , N'AllowInProcess' , 1
GO
EXEC master . dbo. sp_MSset_oledb_prop N'Microsoft.ACE.OLEDB.12.0' , N'DynamicParameters' , 1
Brug OPENROWSET-funktionen til ad hoc-forespørgsler.
SELECT * FROM
OPENROWSET('Microsoft.ACE.OLEDB.12.0', 'Excel 8.0;Database=C:\Users\Administrator\Desktop\Application.xlsx;HDR=YES', 'SELECT * FROM [Application$]');
SELECT * FROM
OPENROWSET('Microsoft.ACE.OLEDB.12.0', 'Excel 8.0;Database=C:\Users\Administrator\Desktop\Application.xlsx;HDR=YES', 'SELECT * FROM [Device$]');
SELECT * FROM
OPENROWSET('Microsoft.ACE.OLEDB.12.0', 'Excel 8.0;Database=C:\Users\Administrator\Desktop\Application.xlsx;HDR=YES', 'SELECT * FROM [User$]');
Til oprettelse af en sammenkædet server til Excel 2007-2013-format:
USE MSDB
GO
EXEC sp_addLinkedServer
@server= 'XLSX_MATRIX',
@srvproduct = 'ACE 12.0',
@provider = 'Microsoft.ACE.OLEDB.12.0',
@datasrc = 'C:\Users\Administrator\Desktop\Application.xlsx',
@provstr = 'Excel 12.0; HDR=Yes'
Forespørg nu din excel-fil på to måder:
SELECT * FROM OPENQUERY (XLSX_MATRIX, 'Select * from [Application$]')
SELECT * FROM OPENQUERY (XLSX_MATRIX, 'Select * from [Device$]')
SELECT * FROM OPENQUERY (XLSX_MATRIX, 'Select * from [User$]')
SELECT * FROM XLSX_MATRIX...[Application$]
SELECT * FROM XLSX_MATRIX...[Device$]
SELECT * FROM XLSX_MATRIX...[User$]