Skip to content

AttributeError: 'MergedCell' object attribute 'hyperlink' is read-only

Bitbucket Importer requested to merge bitbucket/merged-pr-327 into branch/2.6

Created originally on Bitbucket by Dmitry Ferens (Dmitriy Ferens)

Was already merged in Bitbucket before import, marked as merged by the import user


I found that openpyxl fails to load spreadsheets, which contains links which made on merged cells.

Example: bugfix-merged-link.xlsx


  File "", line 16, in get_spreadsheet
    wb = openpyxl.load_workbook(file_path)
  File "site-packages/openpyxl/reader/", line 312, in load_workbook
  File "site-packages/openpyxl/reader/", line 274, in read
  File "site-packages/openpyxl/reader/", line 228, in read_worksheets
  File "site-packages/openpyxl/worksheet/", line 403, in bind_all
  File "site-packages/openpyxl/worksheet/", line 369, in bind_hyperlinks
    cell.hyperlink = link
AttributeError: 'MergedCell' object attribute 'hyperlink' is read-only

It fails to set an attribute on a MergedCell instance, on second loop iteration:

cell       = <MergedCell 'Sheet'.B18>
link       = <openpyxl.worksheet.hyperlink.Hyperlink object>
ref='A18', location=None, tooltip=None, display='', id=None
rel        = <openpyxl.packaging.relationship.Relationship object>
Type='', Target='../', TargetMode=None, Id='rId1'
row        = (<Cell 'Sheet'.A18>, <MergedCell 'Sheet'.B18>)

A proposed fix is to remove that loop completely. I checked coverage and I found that tests never check such case (row has always 1 cell):

I added a possible test improvement and a possible solution, could you please take a look?


Merge request reports