How to get all Sheet names of excel using modern activities

Well u can get it with GET WORKBOOK SHEETS activity
Download example here

https://www.uipath.com/hubfs/Documentation/WorkflowExamples/18.3%20Examples/Excel/Get%20Workbook%20Sheets.zip

Or u can try this also

Or

If that’s the case then u can try with coding options

Like

Using vb net on invoke code activity

Dim excelApp As Microsoft.Office.Interop.Excel.Application
Dim excelBook As Microsoft.Office.Interop.Excel.Workbook

' Provide the path to your Excel file
Dim filePath As String = "YourFilePath.xlsx"

' Initialize Excel Application
excelApp = New Microsoft.Office.Interop.Excel.ApplicationClass()

' Open the Excel workbook
excelBook = excelApp.Workbooks.Open(filePath)

' Create a list to store sheet names
Dim sheetNames As New List(Of String)

' Loop through each worksheet and add its name to the list
For Each sheet As Microsoft.Office.Interop.Excel.Worksheet In excelBook.Sheets
    sheetNames.Add(sheet.Name)
Next

' Close the workbook and Excel application
excelBook.Close(False)
excelApp.Quit()

' Release COM objects to prevent memory leaks
System.Runtime.InteropServices.Marshal.ReleaseComObject(excelBook)
System.Runtime.InteropServices.Marshal.ReleaseComObject(excelApp)

' Now, the sheet names are stored in the sheetNames list
' You can use them as needed

Using python with “Run Python Script” activity

import pandas as pd

# Provide the path to your Excel file
file_path = "YourFilePath.xlsx"

# Read the Excel file into a Pandas DataFrame
xls = pd.ExcelFile(file_path)

# Get the sheet names
sheet_names = xls.sheet_names

# Output the sheet names
print(sheet_names)

Hope this helps

Cheers @aslam_ali1

1 Like