简体   繁体   English

使用SSIS包将多个Excel文件导入SQL Server 2008 R2?

[英]Import multiple Excel files into SQL Server 2008 R2 using SSIS Packages?

I have to insert data into two tables from two different excel sheets using SSIS packges. 我必须使用SSIS包从两个不同的Excel工作表中将数据插入到两个表中。

So, please some one tell me How to import multiple Excel files into SQL Server 2008 R2 using SSIS Packages? 那么,请有人告诉我如何使用SSIS包将多个Excel文件导入SQL Server 2008 R2?

Use Foreach Loop Container --> Foreach File Enumerator. 使用Foreach循环容器 - > Foreach文件枚举器。 Then put your Data Flow in Foreach Loop Container. 然后将您的数据流放在Foreach循环容器中。 Table structure and sheet name have to be equal in every Excel file. 每个Excel文件中的表结构和工作表名称必须相同。

Here is nice tutorial: http://bi-polar23.blogspot.com/2007/08/loading-multiple-excel-files-with-ssis.html 这是一个很好的教程: http//bi-polar23.blogspot.com/2007/08/loading-multiple-excel-files-with-ssis.html

since you have only 2 excel files and only two tables I don't see why use a foreach loop. 因为你只有2个excel文件,只有两个表我不明白为什么要使用foreach循环。 Just follow this link and do it directly 只需点击链接即可直接进行操作

If you need to insert from both excel files to both databases you can use a multicast component to create a copy of a dataset 如果需要从两个excel文件插入到两个数据库,则可以使用多播组件创建数据集的副本

You can create and use variables to hold Excel file path, then implement the package within a for-each-loop container to loop trough each excel files in the folder. 您可以创建和使用变量来保存Excel文件路径,然后在for-each-loop容器中实现该包,以循环遍历文件夹中的每个excel文件。 Make sure that the files are having similar data format and same extension. 确保文件具有相似的数据格式和相同的扩展名。 Create an integration service project in Visual Studio and follow the steps below: 在Visual Studio中创建集成服务项目,并按照以下步骤操作:

  1. Right Click on canvas and add Variable say "FilePath" and set type as String 右键单击画布并添加Variable say“FilePath”并将type设置为String

  2. Drag a for-each loop to canvas 将for-each循环拖到画布上

在此输入图像描述

  1. Right click on for-each-loop and select "Edit" and add path and file extension and then select the variable from "Variable Mapping" tab as shown: 右键单击for-each-loop并选择“Edit”并添加路径和文件扩展名,然后从“Variable Mapping”选项卡中选择变量,如下所示:

在此输入图像描述

在此输入图像描述

  1. Add a Data-flow task in to the loop and double click to open it. 将数据流任务添加到循环中,然后双击打开它。

在此输入图像描述

  1. Add an Excel source and OLEDB destination (if destination is SQL Server). 添加Excel源和OLEDB目标(如果目标是SQL Server)。 By right clicking on these controls and choosing "Edit", you can select appropriate folder for Excel and its Data Sheet as well as specify SQL server database credentials in the destination. 通过右键单击这些控件并选择“编辑”,可以为Excel及其数据表选择适当的文件夹,并在目标中指定SQL Server数据库凭据。 Connect source and destination using blue arrow. 使用蓝色箭头连接源和目标。 Check and modify mappings between columns, if needed. 如果需要,请检查并修改列之间的映射。

在此输入图像描述

在此输入图像描述

在此输入图像描述

  1. Create an expression to read each file to the variable. 创建表达式以将每个文件读取到变量。 This can be done by selecting created "ExcelConnectionManager" and select its "Expression" property and expand to set variables to "ExcelFilePath" 这可以通过选择创建的“ExcelConnectionManager”并选择其“Expression”属性并展开以将变量设置为“ExcelFilePath”来完成。

在此输入图像描述

在此输入图像描述

  1. And that is it. 就是这样。 You are ready to execute the package by coming to Control flow tab and select "Start". 您可以通过进入“控制流”选项卡并选择“开始”来执行包。 在此输入图像描述

Ref: https://www.encorebusiness.com/blog/import-data-from-multiple-excel-files-sql-ssis/ 参考: https//www.encorebusiness.com/blog/import-data-from-multiple-excel-files-sql-ssis/

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM