We have a set of text files that contains information about players of English Premier League. There is one text file for each football club. We want to push all this infomration in a Excel Workbook. There are 2 ways of pushing the data into excel workbook. Either push all the text files information into a sngle work sheet in a workbook OR create a work sheet for each text file and then push the data in corresponding work sheet.
Now, I have 3 text files in F:\MyStuff\EPL folder. All these 3 text files store name of a player, his country and number of goals scored. So in total there are 3 columns in all thes 3 text files.
I have a excel workbook EPL.xls in F:\MyStuff\EPL folder and all the records are to be pushed into this workbook. By default there are some work sheets (Sheet1,Sheet2..). Keep only one sheet and delete others. Rename the only sheet as SAMPLE and add three columns to it: NAME,COUNTRY,GOALS (Why to add columns??..Well, I will explain it later). Declare 3 variables FileName- to capture the name of the text file inside for each loop, SheetName- is used to create the name for excel sheet to be created and SQL- is used to frame a Create Table Statement for creating the excel sheet in workbok
Exercise2: Lets create a work sheet for each text file and move the data from each text file to a different excel work sheet. In the above control flow, there is a execute sql task (EST_CREATE_SHEET) which is responsible for creating the worksheets in a work book. So take a execute sql task inside the for each loop and select the Connection type as EXCEL. Then select the excel connection manager created as a part of exercise1 from the drop down box as Connection. Select SQL Source type as variable and select source variable as SQL. Execute SQL Task editor will look like:
"CREATE TABLE " + @[User::FileName] + " (Name VARCHAR(40),Country VARCHAR(40),Goals INT)"
Thisexpression will create a work sheet at each iteration of the for each loop with the name as the name of the text file which gets captured in FileName variable.Aftre this take a Data Flow Task and configure it as the first data flow task was configured only difference is the data access mode in Excel Destination. This time access mode will be Table name or view name variable as shown below:
Execute the package and check the results in excel workbook.
Hi Nitesh,
ReplyDeleteWhy dont you add the followers gadget so that it becomes easier to follow ur blog.
Done Sudeep!!
ReplyDelete