Sibasish Barik
Sibasish Barik

Reputation: 103

How to get the first sheet of an excel workbook using openpyxl?

I'm able to get the desired sheet by using wb["sheet_name"] method but I want to get the first, or let's say the nth sheet, regardless of the name.

wb = load_workbook(filename = xlsx_dir)   # xlsx_dir is the workbook path

ws = wb["Details"]   # Details is the sheet name

Upvotes: 10

Views: 10901

Answers (2)

Dk2210
Dk2210

Reputation: 12

you need to use worksheet function sheet_by_name

sheet =  wb.sheet_by_name("Details")

Upvotes: -6

wstk
wstk

Reputation: 1270

You need to use the worksheets property of the workbook object

ws = wb.worksheets[0]

Upvotes: 32

Related Questions