各シート名を処理できるように、XLSX ファイルの各「シート名」を SSIS の変数に渡そうとしています。一度に 1 つのシート名を取得して変数実行データ フロー タスクに保存し、次に 2 番目のシート名を取得して変数実行データ フローなどに保存します。「Get Excel sheet」でこのスクリプトを処理しています。以下は私のコードです。助けてください。前もって感謝します
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;
}