How to read sheet name of an excel file

Hello I want to read sheet name of an excel file .

I am unable to understand example How to get the Sheet name from Excel

hence want guidance in simple terms

4 Likes

Hello @piyush.2224

Firstly you have to use “Excel application scope” activity to get the workbook from your excel file.

Then, you can obtain all the sheets names of the excel with workbook.GetSheets.

6 Likes

Hey @piyush.2224

please find following sample attached workflow and let me know :slight_smile:

Sheets.xaml (6.9 KB)

Regards…!!
Aksh

3 Likes

In the above solution,I think the typearguement in For each loop should be string

Sheets.xaml (6.9 KB)

5 Likes

Yeah… 2 month ago was working with other things with workbook object. so forgot to change it here . but edited.

Regards…!!

I assumed that. Not seeing you much around these days, seem to be busy?

@vvaidya Yeah kind of trying new things and workload… :frowning:

What about you?..

Work Load will begin from May (a lot) so will be in your shoes then.

haha … now just trying something nasty :stuck_out_tongue: So :smiley: Lets see what future is holding with it for me lol :slight_smile:

i need to get the hidden sheet names in the excel workbook…what should i do

Hey @niridi

You can also get the hidden sheet name as well form Excel Workbook Object.

Test.xlsx (10.9 KB)

hidden sheet.xaml (6.9 KB)

IN the above excel Sheet2 and Sheet6 are hidden.
when you will run the sample still u will be able to get those sheet name with other visible sheet name as well.

Regards…!!
Aksh

1 Like

its working good :slight_smile:

thanks!!!

i want to get only the hidden sheet name instead of getting all the sheets in the workbook

1 Like

The example you provided is not working. I’m getting following error: : Unable to cast COM object of type ‘System.__ComObject’ to interface type ‘Microsoft.Office.Interop.Excel.Worksheet’. This operation failed because the QueryInterface call on the COM component for the interface with IID ‘{000208D8-0000-0000-C000-000000000046}’ failed due to the following error: En sådan grænseflade understøttes ikke (Exception from HRESULT: 0x80004002 (E_NOINTERFACE)).

What is the solution of getting all sheets names within a workbook?

@aksh1yadav do you happen to know how we can get around this issue posted by @Ohrid?
I believe, in my case, it is because the Excel file has a Chart on a sheet.

Excel Package Version 2.3.6682.26635
I tried reinstalling the Excel package and am on the most recent.
I have tried multiple machines and with admin rights.

I am using wb.GetSheets() when the error occurs.

If there isn’t a known solve for this, I will escalate it to UiPath Support.

Regards.

C

Hi @ClaytonM,
Can you try this “WorkBook.GetSheets.ToList()” .

Below It has the example

Regards
Balamurugan

1 Like

Thanks, adding .ToList didn’t help.
It only happens when there is a Chart as one of the sheets.

Hi @ClaytonM,
If possible , can you share the source.

Regards
Balamurugan

I reproduced issue with a new file:

image

Excel file with Chart on a New Sheet: test1.xlsx (11.3 KB)

Thanks.

Hi @ClaytonM,
Yes. You are right. It is giving error only to have the chart. It doesn’t have cells only the chart . I copied chart into another excel file. And tried to get the sheets count . It is working.

Regards
Balamurugan