Loading workbook with comments and use_iterators=True raises NotImplementedError

Issue #256 resolved
Anonymous created an issue

It looks as though when openpyxl tries to read comments with use_iterators enabled, it tries to get a cell which is not possible with use_iterators.

My code is as follows:

import openpyxl
from openpyxl import load_workbook

wb = load_workbook(filename = 'HasComment.xlsx', use_iterators = True)
ws = wb.get_sheet_by_name(name = 'Sheet1') # ws is now an IterableWorksheet

HasComment.xlsx is attached. The following error arises. 

Traceback (most recent call last):
  File "test.py", line 4, in <module>
    wb = load_workbook(filename = 'HasComment.xlsx', use_iterators = True)
  File "/usr/local/lib/python2.7/dist-packages/openpyxl/reader/excel.py", line 134, in load_workbook
    _load_workbook(wb, archive, filename, use_iterators, keep_vba)
  File "/usr/local/lib/python2.7/dist-packages/openpyxl/reader/excel.py", line 205, in _load_workbook
    read_comments(new_ws, archive.read(comments_file))
  File "/usr/local/lib/python2.7/dist-packages/openpyxl/reader/comments.py", line 52, in read_comments
    ws.cell(coordinate=cell).comment = comment
  File "/usr/local/lib/python2.7/dist-packages/openpyxl/reader/iter_worksheet.py", line 265, in cell
    raise NotImplementedError("use 'iter_rows()' instead")
NotImplementedError: use 'iter_rows()' instead

Comments (6)

  1. CharlieC
    • edited description

    Thanks for the report - yes, comments were only added recently and are not supported with iterators. It shouldn't be too difficult to do this but not before the next version.

    @lolnic can you have a look at this?

  2. CharlieC

    Fixing the exception would be great as it could be included in 1.8.2

    Looking at harmonising the interface of IterableWorksheet with that of normal worksheets in 1.9

  3. Log in to comment