Range slices of Worksheet fail with undefined values
With how the Worksheet object works with the following syntax:
toprow = ws[1] #returns row 1
for row in ws: # iterating through all rows
#work on the row
I expected these to work:
for row in ws[2:]:
#work on rows 2 onward
for row in ws[:3]:
#work from row 1 to 3
However, these give the errors
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "[PATH DELETED]\lib\site-packages\openpyxl\worksheet\worksheet.py", line 284, in __getitem__
raise IndexError("{0} is not a valid coordinate or range".format(key))
IndexError: slice(2, None, None) is not a valid coordinate or range
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "[PATH DELETED]\openpyxl\worksheet\worksheet.py", line 284, in __getitem__
raise IndexError("{0} is not a valid coordinate or range".format(key))
IndexError: slice(2, None, None) is not a valid coordinate or range
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "[PATH DELETED]\openpyxl\worksheet\worksheet.py", line 284, in __getitem__
raise IndexError("{0} is not a valid coordinate or range".format(key))
IndexError: slice(None, 3, None) is not a valid coordinate or range
It would be nice to have it implemented such that the unbounded ranges are handled. It looks like self.iter_rows
is being called from the __getitem__
function so I think looking at the None
conditions in the slice would give the necessary values to send to iter_rows
or iter_cols
. If this is desired, I could probably add this to the code.
Thanks, Tom