Import Data from Multiple Excel Files\Folders using SSIS/ETL

Intro: - This article is about SSIS, which is very useful tool provided by Microsoft, so let’s talk about a problem which we (database developers) face may times, and talk about its solution.
Many times we have got data in excel files, on daily bases, or got multiple files at a time having same schema, and we want to import these all in our database. So importing data from these files one by one is very time consuming and boring task.
 Best solution of this problem is ETL, you can create a SSIS package for import multiple excel file data.
Here we will discuss how to create SSIS package.
So let’s start.



Step 1: Create new integration Service Project as “Test”, here I am using visual studio 2010


Step 2: Right click on package and rename it as “ImportMultipleExcelFilesData.dtsx”

Step 3: Now create a folder with sub folder and multiple excel files,

Ex:- E:\Vikas Ahlawat\SampleSSIS\ExcelFiles


But make sure all Excel files have identical schema/format assuming all Excel files above contain data in worksheet “Sheet1”





Excel files Schema:-
Make sure that all three excel file should same schema like below
File1.xlsx’s Schema


Step 5: Right Click on Control Flow Window, and then click on Variables


Now click on Add Variable icon and then add a variable with name “FileName” of string type.



Step 6: Drag and drop foreach-loop container, and Inside it drag and drop “Data flow task”


Step 7: Right-click on the Foreach Loop container and select Edit. Then, Click on Collection “Collection” tab. Assign folder path and file type as shown below


Then go to “Variable Mappings“ tab and map variable created above like below


Step 8: Now double click on “Data Flow Task”
Drag one “Excel Source” task, double click on this to get “Excel Source Editor” Window
Now choose new and new window will open, now browse to your first excel file that is
E:\Vikas Ahlawat\SampleSSIS\ExcelFiles\File1.xlsx
Under “Name of the Excel Sheet” on “Excel Source Editor”, choose Sheet1$


Step 9: Now drag “OLE DB Destination” task, connect “Excel Source” to “OLE DB Destination”
Point this connection to your database and create new table or use an existing table

Step 10: Now go to "Data Flow task"s property and set DelayValidation property value as True. Otherwise it will insert File1 data three times.

Step 11: Now execute your package, and check your table you will find all three file data in your table.

Thanks



Comments

Archive

Contact Form

Send