1

在此处输入图像描述我正在尝试将 XLSX 文件中的每个“工作表名称”传递给 SSIS 中的变量,以便我可以处理每个工作表名称。我想一次获取一个工作表名称,将其存储在变量运行数据流任务中,然后获取第二个工作表名称,将其存储在变量运行数据流中,依此类推。我在“获取 Excel 表”中处理这个脚本下面是我的代码,请帮助我。提前致谢

string connectionString = null;
OleDbConnection excelConnection = null;
DataTable tablesInFile = null;
int tableCount = 0;
DataRow tableInFile = null;
string currentTable = null;
int tableIndex = 0;
string[] excelTables = null;



connectionString = "Provider=Microsoft.ACE.OLEDB.12.0;Data Source=" + "D:\\ETL\\Sample.xlsx;" + ";Extended Properties=\"Excel 12.0 XML;HDR=YES\";";

excelConnection = new OleDbConnection(connectionString);

excelConnection.Open();
tablesInFile = excelConnection.GetSchema("Tables");

tableCount = tablesInFile.Rows.Count;
excelTables = new string[tableCount];

foreach (DataRow tableInFile_loopVariable in tablesInFile.Rows)
{
tableInFile = tableInFile_loopVariable;
currentTable = tableInFile["TABLE_NAME"].ToString();
excelTables[tableIndex] = currentTable;
tableIndex += 1;
}
            Dts.Variables["User::Test"].Value = excelTables[0];

            foreach (String str in excelTables)
            {


                MessageBox.Show(str);
            }

            Dts.TaskResult = (int)ScriptResults.Success;

        }
4

0 回答 0