.hyperlink returns empty string instead of link value ?

Issue #152 resolved
Former user created an issue
c = worksheet.cell('A378')
print c.value
>>> Link text
>>> ''

Did not set a hyperlink, trying to get a link from worksheet cell(s) but always returns empty string ''

Comments (23)

  1. CharlieC

    @mwwu thanks for the file. I think that preserving hyperlinks when reading files is still a way away but we will hopefully get there at some point.

  2. bbinet

    This patch does not really work for me: when I try to load this xlsx file which contains some hyperlinks, I get the following exception:

    $ python
    Python 2.7.9 (default, Mar  1 2015, 12:57:24) 
    [GCC 4.9.2] on linux2
    Type "help", "copyright", "credits" or "license" for more information.
    >>> from openpyxl import load_workbook
    >>> fn='/home/bruno/dev/clustercontroller_modbusclient/clustercontroller/data/SMA_Modbus-TI-en-18.xlsx'
    >>> wb = load_workbook(filename=fn)
    Traceback (most recent call last):
      File "<stdin>", line 1, in <module>
      File "openpyxl/reader/excel.py", line 220, in load_workbook
      File "openpyxl/reader/worksheet.py", line 116, in parse
      File "openpyxl/reader/worksheet.py", line 309, in parse_hyperlinks
        rel = self.ws._rels[link.id]
      File "openpyxl/packaging/relationship.py", line 95, in __getitem__
        raise KeyError("Unknown relationship: {0}".format(key))
    KeyError: 'Unknown relationship: None'
  3. gavinsalam


    I've got openpyxl 2.4.7 with python 2.7.13 and am using the following code to read the attached file, which consists of a single cell with text "hyperlinkTest" and a link to https://google.com/

    #!/usr/bin/env python
    from openpyxl import load_workbook
    wb = load_workbook(filename = 'test-link.xlsx')
    print "A1 value: ", sheet['A1'].value
    print "A1 hyperlink: ", sheet['A1'].hyperlink

    The output of the code is

    A1 value:  hyperlinkTest
    A1 hyperlink:  <openpyxl.worksheet.hyperlink.Hyperlink object>
    ref='A1', location=None, tooltip=None, display=None, id='rId1'

    i.e. the link doesn't appear.

    Thanks in advance for any help.

    Cheers, Gavin

  4. zhanghui

    why I still get None result? My version is 2.4.9, here is my code

    wb = load_workbook(filename)
    ws = wb.get_sheet_by_name(u"固定供应商List")
    print ws['C2'].hyperlink
  5. Log in to comment