Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Adding links to another cell using the xlwt module for Python

Tags:

python

xlwt

I am exporting some information to an excel workbook using the awesome xlwt module for Python. I know that I can have a certain cell contain a hyperlink that points to an external site like this:

    from xlwt import Workbook, Formula
    wb = Workbook()
    sheet = wb.add_sheet('testing links')
    link = 'HYPERLINK("http://stackoverflow.com/"; "SO")'
    sheet.write(0, 0, Formula(link))
    wb.save("testbk.xls")

However, what I actually want to do is something like "drilling through" the document. I want cell A1 from "sheet1" to point to cell F5 in "sheet3" for example.

Does someone know if what I am asking is possible; and if so, what syntax I must use to accomplish that?

like image 749
nooblar Avatar asked Dec 16 '22 11:12

nooblar


2 Answers

As answered on the python-excel forum:

STW to find out how a user does it in Excel:

=HYPERLINK("#Sheet3!F5","some text")
like image 90
John Machin Avatar answered Dec 28 '22 22:12

John Machin


You'd probably want something like this:

# to get to a different sheet in XL, use the sheet name, an !, and then the 
# cell coordinates. In this case, you're going to sheet3, cell F3
link = 'sheet3!F3'
# This is still a formula, so you should link it as such.
sheet.write(0, 0, xlwt.Formula(link))
like image 40
cwallenpoole Avatar answered Dec 28 '22 23:12

cwallenpoole