3 Ways to Get Excel Sheets List using Pandas/openpyxl

In this tutorial, we will show you getting the list of Sheets in an Excel Workbook by using Pandas.

How to get list of sheets in an Excel Workbook

In this tutorial, we will show you getting the list of Sheets in an Excel Workbook by using Pandas.

For the examples, we will use the following Excel Workbook:

Workbook name: “Excel_pandas.xlsx”

It contains the following sheets:

Pandas-sheet-list-excel

Using read_excel method of Data Frame to get sheets list

The example below loads the workbook by read_excel method.

Then we used the data frame’s keys() method to get the list of sheets as follows:

Output:

How to get last sheet name example

The following program displays the last sheet name in the sample Excel Workbook. For that, we used Python len() function as follows:

Result:

Last Sheet Name:  Sheet2

Using openpyxl library to get Sheet name in the Workbook

If you are using openpyxl for working with Excel files, it has also an easy way of getting the list of sheet names in the Workbook.

The following example loads the Excel Workbook by load_workbook and then uses its sheetnames method is used to get the list of sheets.

Code:

Output:

Third way: using Pandas Excel_File to get sheet names

You may also get the sheet names by using the Pandas ExcelFile object.

Use the sheet_names method and you are done:

Result: