我正在尝试在我的Excel文档中添加超链接功能,方法是单击单元格,这会将我带到Excel文档的另一部分。我有下面的代码,当我点击A1时,应该会把我带到A21单元。代码执行得很好,但是当我点击链接时,会弹出一个窗口说“无法打开指定的文件”。我引用单元格的方式有问题吗?或者有更好的方法来完成这个任务吗?在
from win32com.client import Dispatch
excel = Dispatch('Excel.Application')
def main():
CreateLink()
def CreateLink():
cell_location = excel.Worksheets(1).Cells(1,1)
cell_destination = excel.Worksheets(1).Cells(21,1)
cell_text = "Cell A21"
excel.Worksheets(1).Hyperlinks.Add(Anchor=cell_location, Address=cell_destination, TextToDisplay=cell_text)
if __name__ == '__main__':
main()
试试这个:
使用
xlsxwriter
模块来完成它,因为它很简单,have a look at the documentation相关问题 更多 >
编程相关推荐