SSIS导入Excel文件xls/xlsx

发布于 2024-10-19 19:56:10 字数 328 浏览 5 评论 0原文

我需要将Excel文件中的信息导入到数据库中。 我有一个运行 ssis 包的网页,它获取一个 Excel 文件,并将数据加载到数据库中。
现在的问题在于,要处理 xls 或 xlxs 的不同类型的 excel 文件。

SSIS excel 连接管理器,允许您指定要连接到 xlsxlxs 的 excel 文件类型,您不能使用一个连接两种类型的管理器,现在只允许用户始终将 xlxs 文件更改为 xls,然后处理它,有没有一种方法可以根据 excel 文件的类型动态更改连接管理器, 或者当处理不同类型时,我应该只调用两个不同的 SSIS 包。

I have a requirement of importing information from an excel file to a database.
I have a webpage that runs an ssis package, that picks up an excel file, and loads data into a database.
The problem now lies, in the different types of excel files to be processes either xls or xlxs.

SSIS excel connection manager, lets you specify which type of excel file, you will be connecting to either xls or xlxs, you can not use one connection manager for both types, this now only allows the user to always change an xlxs file to xls, then process it, is there a way to dynamically change the connection manager, based on the type of excel file,
or should i just have two different SSIS packages called, when a different type is processed.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

童话里做英雄 2024-10-26 19:56:10

在 SSIS 2008 中,您可以设置与 2007 Excel 文件 (.xlsx) 的连接,然后使用连接管理器上的表达式将 ExcelFilePath 设置为变量的值。该变量的值可以是类型 97-2003 (.xls) 或 2007 (.xlsx),只要工作表名称相同,Excel 源就可以工作。

Excel Connection Manager Expression

我不确定 SSIS 2005 中是否有相同的行为。

In SSIS 2008, you can set a Connection to a 2007 Excel file (.xlsx) and then use an Expression on the Connection Manager to set the ExcelFilePath to be the value of a variable. The value of this variable can be either type, 97-2003 (.xls) or 2007 (.xlsx) and the Excel Source will work, as long as the Sheet names are the same.

Excel Connection Manager Expression

I'm not sure if this is the same behaviour in SSIS 2005.

绅刃 2024-10-26 19:56:10

如果您已经从代码运行 ssis 包,我想这应该相对容易做到。过去一周左右我一直在摆弄代码编辑包,修改变量等非常容易。我知道您还可以访问连接并指定 dtsConfig 文件

                using (var p = app.LoadFromSqlServer(config.PackageName, config.SqlServerName, config.UserName, config.Password, null))
            {

                // changing variables in code
                Variables vars = p.Variables;
                vars["FromDate"].Value= criteria.From;
                vars["ToDate"].Value = criteria.To;
                // using a configfile in code
                p.ImportConfigurationFile(config.ConfigurationFile);
                DTSExecResult result = p.Execute();
                if (result != DTSExecResult.Success)
                {
                    throw new ApplicationException("SSIS Package did not compelte successfully.");
                }

            }

您可能有 2 个不同的配置文件,一个用于 xlsx并打开 xls 连接,并根据上传的 excel 文件扩展名使用适当的配置文件。

If you are running the ssis package from code already, I would imagine this should be relatively easy to do. I have been fiddling around with editing packages from code over the last week or so and it is pretty easy to modify variables etc. I know you can also access the connections and specify a dtsConfig file

                using (var p = app.LoadFromSqlServer(config.PackageName, config.SqlServerName, config.UserName, config.Password, null))
            {

                // changing variables in code
                Variables vars = p.Variables;
                vars["FromDate"].Value= criteria.From;
                vars["ToDate"].Value = criteria.To;
                // using a configfile in code
                p.ImportConfigurationFile(config.ConfigurationFile);
                DTSExecResult result = p.Execute();
                if (result != DTSExecResult.Success)
                {
                    throw new ApplicationException("SSIS Package did not compelte successfully.");
                }

            }

You could potentially have 2 different config files one for xlsx and on for xls connections and use the appropriate config file based on the uploaded excel files extentsion.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文