Deals Of The Week - hours only!Up to 80% off on all courses and bundles.-Close
Introduction
4. Getting a particular worksheet
Summary

Instruction

Excellent! Having the names of all worksheets comes in handy if we need to access a particular worksheet but don't know its exact name. However, if we already know the name, we can access the worksheet in two ways.

Assuming that we've already loaded our xlsx file, we can use the get_sheet_by_name method:

sweets_ws = wb.get_sheet_by_name("sweets")

We can also access the contents of the "sweets" worksheet in the same way we would access a dictionary value: by providing a particular key. In this case, we would write:

sweets_ws = wb["sweets"]

Exercise

In the previous exercise, we checked the names of all worksheets in the january_diet.xlsx file. Access the sheet that contains summary. Assign that worksheet to the summary_ws variable.

From this point on, you don't have to import the load_workbook function again. We've already done that for you.