How to check if a sheet exist in excel file

I perform three seperate filters to an datatable and want to write the results of each filter to it’s own sheet and this several times.
The excelfile is newly created by using an excelapplication scope then it should for each filter read the sheet, merge it with the datatable of the filter and write it back, since sheet2 and sheet3 don’t exist, I need some kind of if to check if the sheet exists before reading it. I don’t have a workBook variable only a path, how would I be able to achieve this?
I tried using get the get WorrkBookSheets activity in the application scope and then used an if to check if the outputvariable.contains the sheet, but that didn’t work


In your excel application scope you can use the “Get workbook sheets” activity. Save the output to a list<string> variable I’ll call xlSheets. Then in your if statement it should be if xlSheets.contains(“YourSheetName”)

I see your edit now, it looks like you already tried this. The above code works fine for me, can you do a for each loop over your list of strings and use write line to output the results? Make sure the output is what you expect


Hi Dave

Thanls for your quick response, the above discribed know also works for me, I had a typo :slight_smile:

1 Like

This topic was automatically closed 3 days after the last reply. New replies are no longer allowed.