Creating a hyperlink for a excel sheet: xlsxwriter

萝らか妹 提交于 2021-02-09 04:29:15

问题


Is it possible to create a hyperlink for a specific sheet of an excel file?

I want to open a sheet on the click of a cell which is on another sheet of the same excel file. For example, if someone clicks on 'A1' cell which is in the sheet2 the sheet1 will be opened and both the sheets are in the abc.xlsx file.


回答1:


You can do this with the XlsxWriter Worksheet write_url() method using the internal: URI. See the XlsxWriter docs on write_url().




回答2:


I was unable to get this to work using the "write_url(A1, "internal:'sheet name'!A2")" form. Can someone provide some guidance on this?

I was able to successfully add hyperlinks to internal cells using the form:

write('A1', '=HYPERLINK(CELL("address", 'sheet name'!A2), "Friendly Name")

NOTE: the word 'address' is literal/not a generic reference, and, the quotes need to be specified as shown (i.e., single quotes for a multi-word sheet name, and double quotes for the word 'address' and the 'Friendly Name'...




回答3:


To put a "Friendly Name" in the hyperlink use the string argument of write_url() method. For example, I did the following after setting the variable sheet_name, which in this case is both the name of the sheet to link to and the friendly name:

write_url(row, col, f"internal:'{sheet_name}'!A1", string=sheet_name)


来源:https://stackoverflow.com/questions/50369352/creating-a-hyperlink-for-a-excel-sheet-xlsxwriter

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!