.hyperlink returns empty string instead of link value ?

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

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

Comments (22)

  1. 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
        ws_parser.parse()
      File "openpyxl/reader/worksheet.py", line 116, in parse
        dispatcher[tag_name](element)
      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'
    >>>
    
  2. gavinsalam

    Hi,

    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')
    sheet=wb.worksheets[0]
    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>
    Parameters:
    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

  3. 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
    
  4. Log in to comment