Hyperlinks to another tab within the same workbook

2,876 views
Skip to first unread message

CJ

unread,
Dec 5, 2011, 5:11:05 PM12/5/11
to openpyxl-users
Can anybody help me with hyperlinks? I have a multi-tab workbook and I
am trying to create hyperlinks between the tabs... to a specific cell.
What I have tried looks like the following:

from openpyxl.workbook import Workbook

wb = Workbook()
wsIndex = wb.create_sheet()
wsIndex.title = 'Index'
ws = wb.create_sheet()

currentCell = ws.cell(row = 1, column = 2)
currentCell.value = 'Index Tab'
currentCell.hyperlink = wsIndex.cell(row = 3, column = 4)

This fails and give the following error:

AttributeError: 'Cell' object has no attribute 'replace'

Thanks for any help.

Cheers, CJ

Matt

unread,
Dec 29, 2011, 11:32:47 AM12/29/11
to openpyxl-users
CJ,

When I create hyperlinks between worksheets, I use the following
format.

Assuming Target Sheet Name = 'Index', Target Cell = D3:

currentCell.value = 'Index Tab'
currentCell.hyperlink = '#%s!%s' % ('Index','D3') Or '#Index!D3'

Hope this helps!

-Matt

CJ

unread,
Jan 13, 2012, 1:17:49 PM1/13/12
to openpyxl-users
Matt,

Thank you. Your example was exactly what I needed. I am fairly new to
Python and very new to openpyxl. Thanks again.

Cheers, CJ
Reply all
Reply to author
Forward
0 new messages