【发布时间】:2019-06-07 21:46:30
【问题描述】:
我使用 SSIS 加载具有不同工作表名称但结构相同的 xlsx 文件。我只需要加载每个文件的第一张纸,但每次名称不能相同,因此无论名称如何,我都需要始终指向第一张纸。我认为在 Excel 源任务中的数据访问模式下无法使用 index(1st) 这就是为什么我尝试使用任务脚本来获取每个文件的第一张工作表的名称并将其放入变量 Sheet_name 和在每个文件的数据访问模式下使用它。
上面的代码有异常,不知道怎么解决。
我试图在不使用脚本的情况下寻找解决方案,但没有找到,这就是我试图让我的代码工作的原因。
public void Main()
{
String FolderPath =
Dts.Variables["User::Folder_To_Be_Processed_Path"].Value.ToString();
String File_Name = Dts.Variables["User::File_Name"].Value.ToString();
string fileFullPath = "";
fileFullPath = FolderPath + "\\" + File_Name;
string connString = "Provider=Microsoft.Jet.OLEDB.12.0;Data Source=" +
fileFullPath + ";Extended Properties=\"Excel 12.0;HDR=YES\";";
using (OleDbConnection conn = new OleDbConnection(connString))
{
conn.Open();
MessageBox.Show(connString);
dtSchema = conn.GetOleDbSchemaTable(OleDbSchemaGuid.Tables, new object[] {
null, null, null, "TABLE" });
Dts.Variables["User::Sheet_Name"].Value= dtSchema.Rows[0].Field<string>
("TABLE_NAME");
}
Dts.TaskResult = (int)ScriptResults.Success;
}
【问题讨论】:
标签: c# sql-server excel ssis etl