我需要检查Excel文件中包含C#中特定标题的工作表。
工作表名称,顺序和数量是可变的。我需要检查包含特定标题的图纸的所有图纸,然后将名称存储在变量中以便以后处理。
我目前可以获取所有工作表名称,但我无法检查它是否包含我要查找的内容。
目标是获取工作表名称并将其插入SQL语句中以处理SSIS包中的文件。
这是我目前使用的代码:
public void Main()
{
string excelFile;
string connectionString;
OleDbConnection excelConnection;
DataTable tablesInFile;
string[] excelTables = new string[5];
excelFile = Dts.Variables["User::var_MonitoringFile"].Value.ToString();
connectionString = "Provider=Microsoft.ACE.OLEDB.12.0;" +
"Data Source= "+ excelFile +
";Extended Properties=\"EXCEL 8.0;HDR=YES; IMEX=1;\"";
excelConnection = new OleDbConnection(connectionString);
excelConnection.Open();
tablesInFile = excelConnection.GetSchema("Tables");
DataRow tableInFile = tablesInFile.Rows[0];
Dts.Variables["User::var_ExcelSheet"].Value = tableInFile["TABLE_NAME"].ToString();
excelConnection.Close();
Dts.TaskResult = (int)ScriptResults.Success;
}