Import Data from Multiple Excel Sheets using SSIS

  • Hi friends,

    Can anyone help me out how to extract data from multiple excel sheets (same excel doc having multiple sheets) using SSIS 2005

    Thanks,

    Purushoth

  • 1. You need 1 Data Flow Task, containing an EXCEL source Connection and a SQL destination connection

    2. Script Task to get list of sheets within the excel file

    3. For Each ADO Loop Enumerator to loop through sheets

    You also need to dynamically set source connection using variables/expressions. Currently, I don't have a working example/sample of it. May be you can look BOL for information on above.

    --Ramesh


  • Ramesh,

    Thanku very much for ur help.. i ll try and get back to u if i get any doubt..

    Happy Programming!!!

  • There is a reasonably useful article on TechNet that describes most of the work needed to import data from multiple worksheets in an Excel file with SSIS.

    http://technet.microsoft.com/en-us/library/ms345182.aspx

    However, the last step in this article leaves you with a number of assumptions. Once you have followed all the steps listed in the technet article, this is what you have to do.

    1. Add a Data Flow task to the For Each loop container.

    2. In the Data Flow container, add an Excel Source component.

    3. Set the OLE DB connection manager to the Excel connection manager that you would've already setup.

    4. Change Data access mode for the Excel Source component to 'Table name or view name variable'. This will allow you to use the variable name to specify the name of worksheet, instead of hard coding it.

    Note: You may want to use a specific sheet within the Excel file first in order for SSIS to pickup the various column names. Once you are done with the column mapping, you can change this setting back to variable name.

    Now you can continue on with whatever you want to do with the data that is read from each worksheet, one worksheet at a time.

    Hope this helps.

    -- Adnan

  • I made an example for those people that still need:

    http://biresort.net/blogs/pedrocgd/archive/2009/08/06/stepbystep-ssis-extract-data-from-multiple-excel-worksheets.aspx

    I hope this help.

    regards,

    Pedro

    http://www.pedrocgd.blogspot.com

  • Pedro Perfeito (8/6/2009)


    I made an example for those people that still need:

    http://biresort.net/blogs/pedrocgd/archive/2009/08/06/stepbystep-ssis-extract-data-from-multiple-excel-worksheets.aspx

    I hope this help.

    regards,

    Pedro

    http://www.pedrocgd.blogspot.com[/quote%5D

    That URL no longer seems to work, I don't suppose you still have that information posted somewhere else?

  • The site is temporarly down... I can send the paper I made to all those interesed on it.

    Check my email in my BLOG profile and I imediatly send it to you while the site is down.

    Regards,

    Pedro

    http://www.pedrocgd.blogspot.com

  • Hi there,

    Thanks for posting the link http://technet.microsoft.com/en-us/library/ms345182.aspx.

    However, you also wrote that we can add an Excel Source task in the Data Flow afterwards. And in the Excel Source, select the excel connection that we've already made.

    I think it's incorrect. If we follow the link, the connection we create is an ADO.NET connection, not a OLE DB connection, which is what the Excel Source required.

    Could you please correct that and advise what to do after the Foreach Loop is configured?

    Thanks heaps.

  • Thanks abader. It help me to solve the problem.

  • For anyone still working on this, I found out how to pass the table name gathered in the ADO NET enumerator to the Excel source in the data flow.

    1. Inside the ADO NET enumerator, add a data flow task.

    2. Inside the data flow task, add an Excel source.

    3. Open the Excel source, and point to the Excel data source set up in the file enumerator.

    4. Select one of the sheets that shows in the drop down.

    5. Close the Excel source.

    6. Select the Excel source.

    7. In the properties window, copy the name of the sheet you selected. It's in the 'OpenRowset' property.

    8. Set this as the intitial string in your sheet name variable created to gather the sheet name from the ADO NET enumerator.

    9. Select the Excel source.

    10. In the properties window, change the 'AccessMode' to OpenRowset From Variable. This will change the property 'OpenRowset' to 'OpenRowsetVariable'.

    11. Change the 'OpenRowsetVariable' to the variable created to hold the sheet name via the dropdown.

    12. Open the Excel source. You should see your variable as the sheet name.

    13. Click the 'Columns' tab to verify you can connect and mess with columns.

    -------------------------------------------------------------------------------------------------
    My SQL Server Blog

  • This may go without saying, but this is only a viable solution if every worksheet that you want to consume shares the same columns/data you want to consume, because they will all need to map to the same destination. You could create a DSV and some named queries on your excel source to get around column names not matching in different sheets, but the data will ultimately end up in one table.

  • Thanks everyone for putting up your suggestions. However, I have an additional requirement to the above. That is, I want to load data from multiple sheets of a single excel workbook to multiple SQL tables. All the sheet have different set of columns and I don't know how to dynamically change the mapping of columns between source sheets and the respective destination tables. If anyone has already implemented this, kindly share the valuable ideas. I am using MS Excel - 2007 and SQL/SSIS 2008 R2

    Thanks,

    Ashish

  • Thanks for doing the lead up work on this, it should be a good starting point for what I am working on 😀

  • [font="Verdana"]I came across with a very detailed example. Please refer : http://stackoverflow.com/questions/7411741/how-to-loop-through-excel-files-and-load-them-into-a-database-using-ssis-package

    [/font]

    MH-09-AM-8694

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

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