如何创建超链接到同一工作簿中的其他Excel工作表 [英] How to create a hyperlink to a different Excel sheet in the same workbook
问题描述
我使用的是openpyxl for Python,并尝试创建一个超链接,这将使我进入同一个Excel工作簿中的另一个选项卡。做类似以下的事情创建超链接;然而,当我点击它,它告诉我无法打开文件。
I'm using the module openpyxl for Python and am trying to create a hyperlink that will take me to a different tab in the same Excel workbook. Doing something similar to the following creates the hyperlink; however, when I click on it, it tells me it can't open the file.
from openpyxl import Workbook
wb = Workbook()
first_sheet = wb.create_sheet(title='first')
second_sheet = wb.create_sheet(title='second')
first_sheet['A1'] = "hello"
second_sheet['B2'] = "goodbye"
link_from = first_sheet['A1']
link_to = second_sheet['B2'].value
link_from.hyperlink = link_to
wb.save("C:/somepath/workbook.xlsx")
我承担的问题在于'link_to'的价值;然而,我不知道需要改变什么,或者我将要写什么样的路径。
I'm assuming the issue lies in the value of 'link_to'; however, I don't know what would need changed or what kind of path I would have to write.
我使用的是Python 2.7.6和Excel 2013。 / p>
I'm using Python 2.7.6 and Excel 2013.
推荐答案
支持openpyxl中的超链接目前非常基本,主要限于阅读现有文件中的链接。
Support for hyperlinks in openpyxl is currently extremely rudimentary and largely limited to reading the links in existing files.
这篇关于如何创建超链接到同一工作簿中的其他Excel工作表的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!