openpyxl how to switch default sheet

Kobe Nein picture Kobe Nein · Jan 7, 2016 · Viewed 12.6k times · Source

My xlsx file has 5 sheets, I can change fourth sheet content, after change, I save to a new file.

But when I open the new file, I need manual to select the fourth sheet.

How can I change the default sheet to fourth sheet?

Thanks!


update

It`s work! Thank you very much. But still a little question,

first and fourth sheet both select

I want this only fourth sheet select

Answer

Charlie Clark picture Charlie Clark · Jan 7, 2016

Simply set wb.active to the index of the sheet, eg. wb.active = 3 for the fourth sheet.