Search code examples
sql-serverexcelt-sqlexport-to-excelopenrowset

Using OPENROWSET to export dataset into specific range in Excel sheet


I would like to export data from sql server into an Excel sheet. The sheet is structured and has more than one table.

Is there a way to specify an export range or is it limited to sheet only?

insert into opendatasource(
    'Microsoft.ACE.OLEDB.12.0', 
    'Data Source=Mypath\MyFile.xlsx;Extended Properties=Excel 12.0')...[MySheet$]

And I need specify something like:

[MySheet$].MySpecificTable or
MySheet$MySpecificTable or
MySheet$I4:M8

excel screenshot

I don't want use the export wizard - this task should be automated. I know how to do this in C# or SSIS or VBA, but I want know how to do this via OPENDATASOURCE or OPENROWSET.


Solution

  • There is no way how to do this via opendatasource/openrowset...

    Opendatasource is half-unproduced functionality. It's probably not done to work with data but only for ad-hoc connections.