Using hyperlinks causes charts to break

Issue #88 resolved
mfuller20
created an issue

When adding a Hyperlink value to a cell in a worksheet that has a chart, I receive the error:

"Excel found unreadable content in 'chart.xlsx'. Do you want to recover the contents of this workbook? If you trust the source of the workbook, click Yes."

Upon clicking yes, I discover that the chart does not exist, but the hyperlink does, and works.

When removing the line (#52 in attached file) involving the hyperlink, the chart is created without issue.

Comments (10)

  1. edwardsnj

    Bump. I have the same issue with hyperlink and images together. Each works individually, but the output is not valid with both. Same error message as the above issue. Minimal example based on the website example for images...

    import openpyxl
    wb = openpyxl.workbook.Workbook()
    ws = wb.worksheets[0]
    img = openpyxl.drawing.Image('logo.png')
    ws.add_image(img)
    ws.cell(row=0,column=0).value = "TEXT"
    ws.cell(row=0,column=0).hyperlink = "http://google.com"
    wb.save('logo.xlsx')
    
  2. mfuller20 reporter

    There is no python error or traceback, only the following Excel error when opening the workbook:

    "Excel found unreadable content in 'logo.xlsx'. Do you want to recover the contents of this workbook? If you trust the source of this workbook, click Yes."

    The problem is that the openpyxl assigns the hyperlink and the chart to the same relationship ID. In my case, r:id="rId1" for both objects. Changing the chart to rId2 in the worksheet and the relationship xml file allows the Excel to open.

  3. Charlie Clark

    I spent some time looking at this. Unfortunately due to the way relations are split across the xlsx file archive I don't see a quick fix for this. The advice in the meantime would be to disable hyperlinks.

  4. Log in to comment