Hi,
I'm not sure if this is a bug or the documentation is out of date. I'm in the process of up'ing a codebase from using version 2.3.5 to 2.4.1 and came across this differing behaviour. Consider the following trivial sample code:
(ve)$ cat /tmp/test.py
from openpyxl import Workbookfrom openpyxl.reader.excel import load_workbook
wb = Workbook(write_only=True)ws = wb.create_sheet()ws.append(('LAST NAME', 'FIRST NAME', 'Email address'))ws.append(('John', 'Smith', 'jo...@gmail.com'))ws.append(('Jane', 'Doe', 'ja...@gmail.com'))ws.append(('Harry', 'Potter', 'ha...@gmail.com'))wb.save('/tmp/test.xlsx')
wb = load_workbook(filename='/tmp/test.xlsx', read_only=True)assert wb.get_sheet_names() == ['Sheet'], wb.get_sheet_names()ws = wb['Sheet']print (ws.max_column, ws.max_row, ws.min_column, ws.min_row)ncells = 0for row in ws: cells = tuple(row) ncells += len(cells) print cellsassert ncells == 12, ncells
When run with v2.3.5, this code behaves as I'd expect it to:
(ve)$ pip install openpyxl==2.3.5
...
(ve)$ python /tmp/test.py
(None, None, 1, 1)
(<openpyxl.cell.read_only.ReadOnlyCell object at 0x7f2f48b496b0>, <openpyxl.cell.read_only.ReadOnlyCell object at 0x7f2f48b49710>, <openpyxl.cell.read_only.ReadOnlyCell object at 0x7f2f48b49770>)
(<openpyxl.cell.read_only.ReadOnlyCell object at 0x7f2f48b497d0>, <openpyxl.cell.read_only.ReadOnlyCell object at 0x7f2f48b49830>, <openpyxl.cell.read_only.ReadOnlyCell object at 0x7f2f48b49890>)
(<openpyxl.cell.read_only.ReadOnlyCell object at 0x7f2f48b496b0>, <openpyxl.cell.read_only.ReadOnlyCell object at 0x7f2f48b49710>, <openpyxl.cell.read_only.ReadOnlyCell object at 0x7f2f48b49770>)
(<openpyxl.cell.read_only.ReadOnlyCell object at 0x7f2f48b497d0>, <openpyxl.cell.read_only.ReadOnlyCell object at 0x7f2f48b49830>, <openpyxl.cell.read_only.ReadOnlyCell object at 0x7f2f48b49890>)
When run with v2.4.1 (or v2.4.0), this code fails to yield any cells:
(ve)$ pip install openpyxl==2.4.1
...
(ve)$ ./run.sh /tmp/test.py
(None, None, 1, 1)
Traceback (most recent call last):
File "/tmp/test.py", line 21, in <module>
assert ncells == 12, ncells
AssertionError: 0
Has some part of this API changed that I can't seem to find the documentation for, or is this a bug? If it's a fail on my behalf, can someone please point me at the documentation for the change in behaviour here?
Cheers,
Tim