Excel将多个工作簿加载到SQL Server中

介绍 (Introduction)

大约一年前,我正在从事一个项目,该项目围绕每日数据负载(来自企业中的各种资产管理组)到主SQL Server数据存储库中进行。 每个小组在自己的Excel工作簿中完成并发布自己的每日数据。 然后将这些Excel工作簿放置在公共目录中,然后加载到Corporate SQL Server数据库中。 让我们看看如何实现这一目标。 简而言之,我们将创建一个程序包,该程序包将处理给定目录中的所有电子表格。

入门 (Getting started)

For our current discussion we shall be looking at two Excel workbooks. Rest assured that the process works for any number of workbooks. The screen dump below show the financial1 sheet for the financial1.xlsx workbook.

对于当前的讨论,我们将看两本Excel工作簿。 请放心,该过程适用于任意数量的工作簿。 下面的屏幕转储显示了financial1.xlsx 工作簿 financial1

screen dump

Our next screen shot shows the financial1 worksheet for the financial2.xlsx workbook.

我们的下一个屏幕截图显示了financial2.xlsx工作簿的financial1工作表。

First Worksheet

In summary we shall be dealing with:

总而言之,我们将处理:

Workbook name Worksheet name
Financial1.xlsx Financial1
Financial2.xlsx Financial1
工作簿名称 工作表名称
财务1.xlsx 金融1
Financial2.xlsx 金融1

The important point being that the workbooks themselves can have different names HOWEVER the relevant sheets must all have the same name.

重要的一点是,工作簿本身可以具有不同的名称,但是相关的工作表必须都具有相同的名称。

We start by creating a new Integration Services package within SQL Server Integration Services (hence forward referred to as SSIS).

我们首先在SQL Server Integration Services中创建一个新的Integration Services程序包(因此向前称为SSIS)。

New IS Package

We give our new project a name (see below)

我们给新项目起一个名字(见下文)

Project Naming

We now find ourselves at our working surface.

现在,我们发现自己处于工作表面。

Working Surface

Please note that I have renamed our SSIS package “LoadExcelWorkbooks” (see upper right).

请注意,我已将SSIS包重命名为“ LoadExcelWorkbooks”(请参见右上角)。

As in past, I now create a connection to my SQLShackFinancial Database (see below).

和过去一样,我现在创建与SQLShackFinancial数据库的连接(请参见下文)。

Create Connection

By right clicking anywhere in the connection manager box I create an OLEDB destination Connection to my SQL Server Database (see below). I also add an “Execute SQL Task” to the work surface. Creating the source is a bit more complex and we shall be discussing this in a few minutes.

通过在连接管理器框中的任意位置单击鼠标右键,可以创建OLEDB 目标连接到SQL Server数据库(请参见下文)。 我还将“执行SQL任务”添加到工作界面。 创建源代码要复杂一些,我们将在几分钟后讨论。

Create Destination

The “Configure OLE DB Connection Manager” screen is then brought into view. I choose my “SQLShackFinancial” connection from the list of existing connections. This connection was created for a previous paper that I wrote for SQL Shack.

然后进入“配置OLE DB连接管理器”屏幕。 我从现有连接列表中选择“ SQLShackFinancial”连接。 此连接是为我为SQL Shack撰写的上一篇文章创建的。

Created Connection

I click OK, and we are brought back to our work surface.

单击“确定”,我们回到工作界面。

Work Surface

Double clicking on the “Execute SQL Task” control brings up the “Execute SQL Task Editor”.

双击“执行SQL任务”控件将弹出“执行SQL任务编辑器”。

Task Editor

The reader will note that I have set the connection string to point to our “SQLShackFinancial” connection and I have entered two si

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值