August 11, 2009 at 8:53 am
hi all,
I have 4 excel files which are to be loaded in a table.
The data flow task when run 4 times to load the excel sheets, works fine.
But when I place it in the Foreach loop container, the loading is successful for one file only.
Reason being that the 4 excel files have different name for work books.
For example, June09.xls has worksheet - June09, July09.xls has worksheet July09.
Is the possible to assign the values of the workbook dynamically ?
Thanks in advance.
August 11, 2009 at 9:29 am
touchmeknot123 (8/11/2009)
hi all,I have 4 excel files which are to be loaded in a table.
The data flow task when run 4 times to load the excel sheets, works fine.
But when I place it in the Foreach loop container, the loading is successful for one file only.
Reason being that the 4 excel files have different name for work books.
For example, June09.xls has worksheet - June09, July09.xls has worksheet July09.
Is the possible to assign the values of the workbook dynamically ?
Thanks in advance.
You have to do the following:
1. Setup a variable, which depends on the current for each iteration and will contain SQL statement to select data from the excel worksheet. Something similar to that:
SELECT COL1, COL2, COL3 FROM $@[User::WorksheetName]
2. In the data flow for your Excel Source choose to use "SQL command from variable" and then select the variable you have setup on the first step.
August 11, 2009 at 11:30 am
Thank you very much! I got it!
August 11, 2009 at 3:23 pm
CozyRoc,
another quick question regarding the same.
I could do it because the woskheet names were extracted from filenames.
How to solve the same issue where the filenames and worksheets aren't related ?
example :
June09.xls , Sheet4
July09.xls , Sheet2
August 11, 2009 at 4:02 pm
touchmeknot123 (8/11/2009)
CozyRoc,another quick question regarding the same.
I could do it because the woskheet names were extracted from filenames.
How to solve the same issue where the filenames and worksheets aren't related ?
example :
June09.xls , Sheet4
July09.xls , Sheet2
You have to setup mapping somewhere that June09.xls maps to Sheet4. You must most probably create custom script task for this.
August 12, 2009 at 1:54 am
Or, if you can be bothered setting things up so that you have access to the Excel object model via script (a bit of a pain), you can get the sheet names in code:
myExcel =CreateObject("Excel.Application")
myWorkBook=myExcel.WorkBook.Open("my Excel File")
Dim tWorkSheet as Excel.Worksheet
For Each tWorkSheet In myWorkBook.Worksheets
myTableName(i) = tWorkSheet.Name
Next tWorkSheet
The absence of evidence is not evidence of absence
- Martin Rees
The absence of consumable DDL, sample data and desired results is, however, evidence of the absence of my response
- Phil Parkin
August 14, 2009 at 9:40 am
Thanks Phil.
I am trying it out your way.
I am having trouble since the dll - 'Microsoft.Office.Interop.Excel' is missing.
I have installed the dll but I do not know how to add it to the project.
The 'Add Reference' in the project doesn't have any browse button 🙁
I have no idea since I am new to .NET.
Please help.
August 14, 2009 at 10:08 am
touchmeknot123 (8/14/2009)
Thanks Phil.I am trying it out your way.
I am having trouble since the dll - 'Microsoft.Office.Interop.Excel' is missing.
I have installed the dll but I do not know how to add it to the project.
The 'Add Reference' in the project doesn't have any browse button 🙁
I have no idea since I am new to .NET.
Please help.
If you are not experienced with .NET I would recommend not to use this approach. In general automation of Excel is quite troublesome and requires too many additional installed components / permissions. Try the other approaches.
August 14, 2009 at 10:17 am
I can learn it if I don't know it with your help 🙂
Other appraoches ?? Can you suggest, how else can it be done ?
August 14, 2009 at 10:29 am
You can also use the OleDB GetSchema() method. I can't remember the exact syntax, but a search of msdn should help.
This allows you to query the excel catalog information without the need for Excel references...
HTH
Kindest Regards,
Frank Bazan
August 14, 2009 at 10:30 am
touchmeknot123 (8/14/2009)
I can learn it if I don't know it with your help 🙂Other appraoches ?? Can you suggest, how else can it be done ?
It will take a couple of years ot learn 😉 And even this will not help with you with the troubles of Excel automation.
Now getting back to the other approach. If you are able to setup mapping between file name and sheet name then I would recommend you stick to this approach.
August 14, 2009 at 10:34 am
Try reading this thread and you'll get an idea of the complexities involved:
http://www.sqlservercentral.com/Forums/Topic531295-148-2.aspx#bm734565
I won't be able to help any further though - I haven't tried it (don't really want Excel installed on my SSIS servers).
If you decide to push ahead with it, good luck to you.
The absence of evidence is not evidence of absence
- Martin Rees
The absence of consumable DDL, sample data and desired results is, however, evidence of the absence of my response
- Phil Parkin
August 14, 2009 at 10:34 am
Frank Bazan (8/14/2009)
You can also use the OleDB GetSchema() method. I can't remember the exact syntax, but a search of msdn should help.This allows you to query the excel catalog information without the need for Excel references...
HTH
Yes, this is exactly what I was thinking, too. You can check this script for ideas how to get the list of available worksheets using the OLEDB Schema method.
August 14, 2009 at 10:46 am
Oh that is a much tidier idea, try that first! Nice one.
The absence of evidence is not evidence of absence
- Martin Rees
The absence of consumable DDL, sample data and desired results is, however, evidence of the absence of my response
- Phil Parkin
Viewing 14 posts - 1 through 13 (of 13 total)
You must be logged in to reply to this topic. Login to reply