Setting active sheet by Sheet instead of index
Created originally on Bitbucket by snorfalorpagus (Joshua Arnott)
The following syntax seems intuitive to me:
#!python
wb = openpyxl.Workbook()
sheet = wb.create_sheet("New Sheet")
wb.active = sheet
This code doesn't raise an exception, until wb.active
is accessed again:
#!python
>>> wb.active
Traceback (most recent call last):
File "<console>", line 1, in <module>
File "C:\Miniconda3\envs\python36\lib\site-packages\openpyxl\workbook\workbook.py", li
ne 134, in active
return self._sheets[self._active_sheet_index]
TypeError: list indices must be integers or slices, not Worksheet
Instead we're required to pass the index:
wb.active = wb.get_index(sheet)
It seems like it should be easy to make the earlier code function as expected by automatically calling get_index
if a Sheet
is passed.