简体   繁体   English

SSIS动态Excel目标文件名

[英]SSIS Dynamic Excel Destination File Name

如何配置数据流任务,该任务从MS SQL Server 2008数据源获取数据并将其放入一个文件名看起来像“日期文件名” .xls的Excel文件中?

Excel is the biggest pain to deal with in SSIS. Excel是SSIS中要处理的最大难题。 Usually I store a template file that just has the column headers and nothing else. 通常,我存储一个模板文件,该文件只有列标题,而没有其他内容。 I start with a task to copy the template file to the processing directory. 我首先执行将模板文件复制到处理目录的任务。 You can use variables to create the file name in an expression at this point. 此时,您可以使用变量在表达式中创建文件名。 Alternatively, you can create the file in the dataflow and then rename the file in a step after the data flow. 或者,您可以在数据流中创建文件,然后在数据流之后的一个步骤中重命名文件。 With text files, I have dynamically created the connection in an expression, but Excel seems to be funny about that. 对于文本文件,我已经在表达式中动态创建了连接,但是Excel对此似乎很有趣。

Provided that your column definition don't change.... you can go to 前提是您的列定义没有更改...。您可以转到

  1. Right Click on Excel Connection Manager 右键单击Excel Connection Manager
  2. Expression 表达
  3. Select connectionstring 选择连接字符串
  4. bulid expression (for Example : (DT_WSTR, 50) GETDATE() + @[user::FileName] +".xlsx") bulid表达式(例如:(DT_WSTR,50)GETDATE()+ @ [user :: FileName] +“。xlsx”)

Select the properties for Excel Connection Manager instance, Click on the ellipsis for 'Expressions 'property and set an expression for 'ExcelFilePath' to a variable with a valid path to an excel file, this takes cares of the connection string. 选择Excel Connection Manager实例的属性,单击“表达式”属性的省略号,然后将“ ExcelFilePath”的表达式设置为变量,该变量具有指向excel文件的有效路径,这将负责连接字符串。

You do need a variable valid excel file at the design time, otherwise connection manager does not work, you can overwrite it at run time using a script task to point to the excel file that does not exist at design time. 在设计时确实需要一个可变的有效excel文件,否则连接管理器将无法运行,您可以在运行时使用脚本任务将其覆盖,以指向设计时不存在的excel文件。

HLGEM's answer certainly helps. HLGEM的回答肯定会有所帮助。 As @sql-rookie requested, I'll provide a sample about how to copy the excel file to a new file named with current date. 按照@ sql-rookie的要求,我将提供一个有关如何将excel文件复制到以当前日期命名的新文件的示例。 Hope this will help others with the same question in the future. 希望这会在将来对其他有相同问题的人有所帮助。

Basically you just need to add an additional File System Task after the Data Flow Task . 基本上,您只需要在“ Data Flow Task之后添加其他File System Task Data Flow Task And use a variable for the Destination File Path: "\\\\\\\\file\\\\"+SUBSTRING((DT_STR,30, 1252) GETDATE(), 1, 10) +".xlsx" 并为目标文件路径使用一个variable"\\\\\\\\file\\\\"+SUBSTRING((DT_STR,30, 1252) GETDATE(), 1, 10) +".xlsx"

在此处输入图片说明

在此处输入图片说明

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

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