C# Excel - Searching Excel worksheet name contains not working properly..

  • Thread starter Thread starter Gani tpt
  • Start date Start date
G

Gani tpt

Guest
I am searching some excel worksheet from my excel workbook.

for example, i am passing the value "97 8" as a sheet, and it should search in the excel workbook using contains.

i have written the below code. but, it always return false.

But, in my excel workbook will have "97" worksheet and it is supposed to be return true.

1622067.jpg

ShtName = "97 8";
public static bool ShtExists(Excel.Workbook xlWB, string ShtName)
{

bool found = false;

// Loop through all worksheets in the workbook
foreach (Excel.Worksheet sheet in xlWB.Sheets)
{
// Check the name of the current sheet
if (sheet.Name.Contains(ShtName))
{
found = true;
break; // Exit the loop now
}
}

if (found)
{
// Reference it by name
}
else
{

}
return found;
}
why it is always return as false...?

Continue reading...
 
Back
Top