Check Sheet Exists by Name

Is there any API that can provide me if a worksheet exists by name like,

bool exists = workbook.Worksheets.CheckIfExists(sheetNameString);

Thanks.

We don't provide such an API. But it's easy to make it with your own code:

public bool CheckSheetName(Worksheets sheets, string sheetName)

{

for(int i = 0; i < sheets.Count; i ++)

{

if(sheets[ i ].Name == sheetName)

return true;

}

return false;

}

I had similar code now as work around but I have around 350 worksheets and I need to loop this in another loop that can go for 500 times because of some business logic and hence not efficient.

Any new efficient API would be really helpful in future.

Thanks for the quick response.

You can put all sheets’ name in a hashtable and check it from this hashtable.

Thanks for the work arounds.

It will make your api complete if either workbook.Worksheets["name"] api returns null instead of throwing exception or a separate api is provided to check if a sheet exists.