How to Dynamically and Iteratively Populate An Excel Workbook from SQL Server

  • Comments posted to this topic are about the item How to Dynamically and Iteratively Populate An Excel Workbook from SQL Server

  • Please, can you explane how do you create ExcelFileName and TAB

    variable.

    I can't see it cleary from the picture.

    radovan

  • Can you provide the SSIS package. It's difficult to see the screen shots and to follow

    For better, quicker answers, click on the following...
    http://www.sqlservercentral.com/articles/Best+Practices/61537/

    For better answers on performance questions, click on the following...
    http://www.sqlservercentral.com/articles/SQLServerCentral/66909/

  • you can simple use output from your SQL Server and call xp_cmdshell to modify/re-massage/rename/move/.. your xls file.

    I did it even within Unix (Excel will open your tab delimited output when you add xls extension to your file).

    I did not like DTS, but SSIS can do the same, but I still prefer to use combination of batch file with ISQL and xp_..

  • Can you post more detail on how you get the filename created and the tab names.

    Can't really make anything out in the pictures

  • Check this link. It has a more detailed sample.

    http://rafael-salas.blogspot.com/2006/12/import-header-line-tables-into-dynamic_22.html

  • What version of SQL Server?

  • Hopefully here are some answers to the questions:

    1. The filename actually is a variable. The variable was populated in the first Execute SQL task BEFORE the Foreach Loop. (Like a cursor). You dump values from a table into a variable.

    Set the Excel Connection (notice that usually you specific connection 1, connection 2 etc but here NO specified number) to use a New Property expression. In the New Property expression and add the variable defined for the Excelsheet name. This variable references back to the cursor (called in this case 'Region' from the Execute SQL task).

    As to the tabs...it is the same thing. A cursor is populated in the Execute SQL task called 'subregion'. This populated cursor is then used in a variable statement in the Foreach loop allowing the tabs to be created. Use the 'User:ListofSubgroups' value in the Variable name field within the Excel Destination Editor to create the tabs on the fly.

    Now...as a 'heads up' To be able to create the Excel Destination the first time when developing the solution an actual Excel workbook with at least one tab must exist.

    2. As with any solution there are definitely more ways than this one to 'skin a cat' and do this operation. This solution does not discuss how to push to 2007 Excel (we have just figured that one out). AND there is actually a way to totally code creation of an excel spreadsheet and tabs and population of same. It is not mine so I will not post here. This solution is for those that use SSIS packages preferentially.

    The original motivator was to be able to do this WITHOUT having a template sitting on some filesystem. To that end we are one step closer to keeping everything in a SSIS solution.

    Hoping the above helps....please keep the questions coming

  • Radovan:

    Were you able to pull down an actual version of the article? If so, you should be able to expand the screen prints. As well, I have posted more explanation here....

  • Hello,

    I like this article. Do you think that I could target a SharePoint portal document library?

    Also, I would like the possibility to create a VBA module in addition to the excel tab.

    Thanks

    Philippe

    BI Guy

  • SQL Server Version = 2005

    Not sure about pushing to a sharepoint doc. Can you give me some more details? You want to push to a specific type of doc? Or is it that you want to push TO the sharepoint?

  • That would be creating on the fly a new Excel in SharePoint doc library with a path similar to this

    http://smportal.onsemi.com/C10/Reporting%20Projects/Development%20Process%20and%20Templates/MyWorkbook.xls

    BI Guy

  • to create the file on the sharepoint site I would try to treat it just as a file address. That means in your variable (see the article for specifics) I would specify the path:

    SHAREPOINT_FILESYSTEM_ADDRESS\20Templates/"+(DT_STR.25.1254)@[User::YOUR_VARIABLE]+"xls"

    Ok, sharepoint has a real, physical filesystem. Push the file to there. Make the directory/folder always visible on sharepoint OR overwrite with the same file name each time and just have the file visible (this was done at one of the sites I was at last year).

    Let me know how it goes.

  • --SQL Server and call xp_cmdshell to modify/re-massage/rename/move/.. your xls file.

    how do you do this? i am using xp_cmshell to output data from a sql table to different tabs in excel. I only get the last set of data in the cursor in the first tab

  • Forum Newbie: Is the last question aimed at this article? The article does not use:xp_cmshell

    But I can say that if you populate the tab cursor from the SQL Execute Task before the Foreach Loop you will definitely get a different tab for each value. Now, to populate each tab with the correct values you need a variable set up for the data pull (cols etc etc) that is also part of the solution.

    IF you want to use xp_cmshell I am afraid I cannot help you. 🙂

Viewing 15 posts - 1 through 15 (of 58 total)

You must be logged in to reply to this topic. Login to reply