How to dynamically set the DataFlowTask : Excel Source in SSIS Package? - sql

How to dynamically set the DataFlowTask : Excel Source in SSIS Package?
I am loading over 100 excel files which has to be passed through Excel Source.
In the Property of Excel Source / OpenRowset , I have the set condition as
" Sheet2$A5:K "
I am able to set the Excel Source for one specific file. However, I am not able to set the source in a dynamic approach of loading 100 files in a folder.

Related

How to fetch the Excel file path connection dynamically through a variable in the Excel Source?

How to fetch the Excel file path connection dynamically through a variable in the Excel Source?
Inside my Foreach Loop Container, I have Excel Source which has Excel Connection String.
I am using the variable to map the Incoming folder path. I set DelayValidation to True.
Folder Path : c:\IncomingPath\
However, I am getting an error as
The connection is not found.
We put the excel files by extracting the zip file. Steps are done through SSIS Package.
In the Foreach Loop make sure it's using the Foreach File Enumerator type if it's not already. Then on the Variable Mappings page, set a string variable to Index 0, this will hold the file name for each iteration of the loop. Then go to the Excel Connection Manager, click on the ellipsis next to the Expressions property (highlight the connection manager and press F4 to view the Properties window) and set the same string variable that was set at Index 0 in the loop as the expression for the ExcelFilePath, not ConnectionString, property. This will set the Excel Source component to use the current file from each iteration of the Foreach Loop.

Dynamic Excel Sheets load into SQL using SSIS

I'm trying to load multiple excel format files (.xlsx) into sql. I have set up my package as followed. My excel files name and sheet name will change daily
File name: PROD File Tracking 02-10.xlsx - Month and Day change daily
Sheet name: 2-10$ -- month and day change daily
Package Structure
For each Loop Container -> Data Flow Task -> Excel Source -> OLE DB Destination
Variables Values
FileName: Z:\Users\darsftp\BDS\GBRTest\PROD File Tracking 02-10.xlsx
FolderPath: Z:\Users\darsftp\BDS\GBRTest
ExtProperties: "Excel 12.0;HDR=Yes"
Need Help
To dynamically pick up file daily with a dynamic sheet name.
I know how to pick up files with a dynamic file name but not with a dynamic sheet name. That's where I'm having the issue.
Create a new variable Sheetname and Set it's property Evaluate as expression to True and use the following expression:
REPLACE(SUBSTRING(#[User::Filename],FINDSTRING(#[User::Filename],"PROD File Tracking", 1 ) + LEN("PROD File Tracking"),100),".xlsx","") + "$"
So if your Filename variable value its Z:\Users\darsftp\BDS\GBRTest\PROD File Tracking 02-10.xlsx so Sheetname variable value will be 02-10$ wich is the sheetname.
And in your Excel Source read the sheetname from variable Sheetname
Side note: Excel sheetname always end with $ sign (it doesn't appear in excel)
Read more about variable and expressions in this article
EDIT 1
You have to add an expression the the Excel connection manager connection string property:
"Provider=Microsoft.ACE.OLEDB.12.0;Data Source="+ #[User::Filename] + ";Extended Properties=\"Excel 12.0;HDR=YES\";"
Set DelayValidation property of Data Flow task to True.
Usefull Links
SSIS with variable excel connection manager
Dynamically assign filename to excel connection string
https://www.google.com.lb/amp/s/sqlserverrider.wordpress.com/2013/01/07/dynamic-file-name-for-excel-connection-manager-ssis/amp/

DataTable.ImportSheet operation failed.Invalid file

I'm running Excel tests on UFT and sometimes I get the error number 20012 which is "DataTable.ImportSheet operation failed.Invalid file".
This is my way of importing the script:
DataTable.ImportSheet filepath,scriptname,"Action2"
filepath is the path of my workbook which conatins many excel sheets (scripts)
scriptname: the name of the script that I want to run
Action2: contains all the call of all possible keywords that may script can contains.
Any help please, why I'm getting this error.
The problem is that this is working well for some scripts and for others not after 3 or 4 run times.
I think the problem is on Excel itself and not on the code, are there any problems when working with Excel 2016 and UFT 12 ?
UFT syntax for importing a worksheet is:
DataTable.ImportSheet FileName, vtSrcSheet, vtDstSheet
This means you need to pass as parameters the filename (and path) to the excel file, the name (or index) of the source sheet you want to import, and then the destination you want this sheet to be (for example "Global" or "Action1" etc)
Unless scriptname happens to be the exact name of the worksheet you are trying to import you will get this error.
If you want to import the whole file use Datatable.Import instead of Datatable.ImportSheet

Data Import from SQL server to Excel sheet SSIS

I'm working on a data export package where I move few data from sql to a excel sheet.
This package is automated to execute every weekend .
Unless i delete the previous excel file , I'm not able to run the package again as it throws the destination table is already present error.
Suggest me a way to retain the old excel file and create a new one everytime.
For example , if the earlier excel sheet was named export_1 , the next sheet on the subsequent week should be named export_2
Create 2 parameteres
File_Path
Connection_String
2.Use a Script task that creates an Excel File and Assign the values to
parameters "File_Path" and "Connection_String" based on the newly
created Excel file
Parameterize the 'Excel Connection'
ConnectionString --> Connection_String
ExcelFilePath --> File_Path
You can dynamically pass the file name through the expressions based on the Datetime.
Ex: Filepath+Date1_mmddyy_hhmmss
Every time the file generates, It will create a file with new file name and Excel file should be passed as an expression.

SSIS Looping through Excel Sheets

I am using SSIS2012, I am trying to import about 25 excel files (each containing about 70(variable) sheets) into SQLserver2008.
I have built it so that it will loop through all the excel sheets and import the first sheet, but this is useless, how can I loop all the excel files and loop all of the sheet names into SQL?
I have set up a script task to get the sheetName into a variable, but I don't know what to do from there.
Is my question clear enough?
I am much more fluent in VB over C# so if you're using script task, ideally paste VB,net code.
Thanks,
James.
You can Loop through Excel Files and Tables by Using a Foreach Loop Container
Here you will use nested foreach loops in the Control Flow. These will loop first over the files, and then loop over the tables within the files (worksheets). Inside the loops you will have a Data Flow with an Excel File Source.
I've done a similar thing. What I did was add a Foreach Loop Container, and set enumerator property to Foreach File Enumerator. Retrieve the file path and store in a variable. Then use that variable to dynamically set the file connection using the property extensions editor.
Finally, put your data flow inside the Foreach Loop Container.
Doing this I was able to import data for each Excel file found in the directory specified.