Foreach Excel Worksheet Enumerator |
Disclaimer
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
Downloads:
You can download a SSIS 2008 and 2012 version on the download page.
Installation
The installer registers the DLL in the GAC and copies it to the ForEachEnumerators folder of SSIS (example: C:\Program Files\Microsoft SQL Server\100\DTS\ForEachEnumerators\). After that you have to close Visual Studio/BIDS because it caches the GAC on startup.
SSIS
The enumerator is automatically added to the Foreach Loop when you open a SSIS project.
The new enumerator |
Do you have an example of this project that you can publish?
ReplyDeleteHi Anonymous, What exactly are you looking for? On MSDN you can find how you can create your own custom enumerator: http://msdn.microsoft.com/en-us/library/ms136120(v=sql.110).aspx
DeleteCan you please explain how this works to read the all data from excel?
ReplyDeleteI assume you now how the foreach loop works. This enumerator returns the excel sheetname. You can use that in the excel source or to create a select query with an expression on a string variable and then use that variable as a source.
DeleteBut you can only use this if the format of all sheets is the same.
If I us this component inside of another Foreach Loop with a file enumerator on. The first Excel file get process 100% but the second one always fails. It looks like it is trying to read as sheet that does not existx. Example Woorbook has 24 sheets, the error that gets displayed "opening a rowset for Sheet25 failed"
ReplyDeleteWhat you could do is add a script task in the loop. Then add the two string variables from the loops as ReadOnlyVariables and then hit the Edit Script Button. In the main method add the messagebox:
Deletepublic void Main()
{
// TODO: Add your code here
MessageBox.Show(Dts.Variables["User::myFilePath"].Value.ToString() + Environment.NewLine + Dts.Variables["User::myExcelSheet"].Value.ToString());
Dts.TaskResult = (int)ScriptResults.Success;
}
This will show which sheet is active and then you can check whether it exists and whether the format is the same as the other sheets.
All my spreadsheets have different number of sheets in it, but the format of the data is the same. I have noticed that it does not reset the enumerator object. example; spreadsheet = 45 sheets & spreadsheet = 24 sheets. when the first file loop go to spreadsheet 2 the enumerator is still trying to import 45 sheets even though it only have 24 sheets.
DeleteAny advice. Thanks for the fast reply
Hi Jean-Pierre, I can not replicate your problem. Could you contact me via the form. Then we can communicate via email... easier/faster.
Delete