Following the instructions on a MSSQLTips blog post, I have setup package with a Foreach Loop to loop through all sheets in a workbook and import the data into a table.
The loop is finding the correct sheet ('11-18$'
), and then the same sheet with a longer name ('11-18$'_xlnm#_FilterDatabase
). The extra sheet is causing data duplication
and error messages such as "Derived Column.Outputs[Derived Column Output].Columns[SourceSheet]" specifies failure on truncation
.
How to make the loop exclude the 'xlnm#_FilterDatabase' object?
Why is the loop duplicating the sheet data?
MSSQLTips blog post-- Read Data From Multiple Excel Worksheets SSIS
Foreach Loop setup:
Variable
- Variable is
Name:'Sheet Name'
,Scope:'Import_AXExtractAgristatsInventory'
(package name),Date type:'String'
,Value:'11-18$'
Foreach Loop Editor
Collection Enumerator is
Foreach ADO.NET Schema Rowset Enumerator
Connection Provider is
.Net Providers for OleDb\Microsoft Office 12.0 Access Database Engine OLE DB Provider
Connection File is a path to
\\filepath\file.XLSX
Connection Advanced Extended Property is
Excel 12.0
Connection Variable Mapping is
Variable:='User:SheetName'
,Index:='2'
Connection string is
Data Source=C:\filepath\file.xlsx;Provider=Microsoft.ACE.OLEDB.12.0;Extended Properties=Excel 12.0;
Update: Foreach ADO.NET Schema Rowset Enumerator
and Set Restrictions
limitation
I thought the Set Restrictions
option would do the trick (to exclude the phantom sheets) with an expression such as !=*_FilterDatabase*
, but according to an ebook excerpt online at flylib, wildcards are not an option ...
The ADO.NET Schema Rowset Enumerator provides a way to enumerate the schema for a data source. For example, you can enumerate the tables in a database, catalogs on a server, or columns for a table. For each schema, you can filter the results in a number of ways. Figure 13.13 shows the Foreach ADO.NET Schema Rowset Enumerator Editor with the Catalogs schema selected.
There is no way to specify a wildcard for restrictions.
Reference: Microsoft SQL Server 2005 Integration Services: Stock Foreach Enumerators
- Figure 13.13. The Foreach ADO.NET Schema Rowset Enumerator provides a way to enumerate database schema.
- Figure 13.14 shows the Tables Schema Restrictions dialog box for the Tables schema.
Update: Debugging values in loop
In an effort to debug the sheet objects in the loop, I finally found a way to stop the loop and display the sheet name. I found an article on Pragmatic Works Blog Post which shows how to use Script Task
, Break Point
, and Watch Window
to display that active loop value-- Looping through resultset with foreach loop.
These are suggested SO questions...