How can I use SSIS or something similar to export data to a number of worksheets in the same Excel spreadsheet?

Filed under: Transact-SQL (T-SQL) — Ari Weil at 5:35 am on Monday, November 26, 2007

This MSDN article has what you’re looking for.

By leveraging OPENROWSET you can take this very simple code template and use it to create what you’re after:


INSERT INTO OPENROWSET('Microsoft.Jet.OLEDB.4.0',
'Excel 8.0;Database=C:\myreportspreadsheet.xls;','SELECT name FROM [Sheet_1$]‘)
SELECT [name] FROM master..sysobjects
INSERT INTO OPENROWSET(’Microsoft.Jet.OLEDB.4.0′,
‘Excel 8.0;Database=C:\myreportspreadsheet.xls;’,'SELECT name FROM [Sheet_2$]‘)
SELECT [name] FROM AdventureWorks..sysobjects
GO

Before you run the aforementioned queries, you need to first make sure you’ve got an Excel spreadsheet on the C drive called myreportspreadsheet.xls with a column named name on both Sheet1 and Sheet2. If you run this as a scheduled Windows task you can add the file creates to the process, thereby ensuring the files exist before the job runs.

No Comments »

No comments yet.

RSS feed for comments on this post. TrackBack URI

Leave a comment

XHTML: You can use these tags: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>