python给excel添加超链接_使用Python将超链接插入到Excel中的本地文件夹

__author__='Paul'importosimportopenpyxlfromopenpyxlimportload_workbookimportxlsxwritersite_info_root='C:\\Users\\paul.EPSCONSTRUCTION\\PycharmProjects\\Excel_Jobs\\Site Information\\'# This function returns the last row on eps.xlsm to be populateddefget_last_row(cell_ref='P1'):#P1 contains the count of the used rowsglobalwbglobalwswb=load_workbook("eps.xlsm",data_only=True)#Workbookws=wb["jobnoeps"]#Worksheetlast_row=ws.cell(cell_ref).value#Value of P1 from that worksheetreturnlast_row# This function will read the job number in format EPS-XXXX-YRdefread_last_row_jobno(last_row_position):last_row_data=[]forcolsinrange(1,5):last_row_data+=str(ws.cell(column=cols,row=last_row_position).value)last_row_data_all="".join(last_row_data)returnlast_row_data_all#This function will return the Customerdefread_last_row_cust(last_row_position):cols=5customer_name=str(ws.cell(column=cols,row=last_row_position).value)returncustomer_name#This function will return the Sitedefread_last_row_site(last_row_position):cols=6site_name=str(ws.cell(column=cols,row=last_row_position).value)returnsite_name#This function will return the Job Discriptiondefread_last_row_disc(last_row_position):cols=7site_disc=str(ws.cell(column=cols,row=last_row_position).value)returnsite_disclast_row=get_last_row()job_no_details=read_last_row_jobno(last_row)job_customer=read_last_row_cust(last_row)job_site=read_last_row_site(last_row)job_disc=read_last_row_disc(last_row)cust_folder=job_customerjob_dir=job_no_details+"\\"+job_site+" - "+job_disc#Insert Hyperlink to folderdeffolder_hyperlink(last_row_position,destination):cols='B'rows=str(last_row_position)position=cols+rowsfinal_position="".join(position)printfinal_position# This is just to check the value# The statement below should insert hyperlink in eps.xlsm > worksheet jobnoeps at column B and last completed row.ws.cell(final_position).hyperlink=destinationfolder_location=site_info_root+job_customer+"\\"+job_dirprintfolder_location# This is just to check the valuefolder_hyperlink(last_row,folder_location)

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
要在Python的tkinter添加超链接,你可以使用Text组件的tag_bind()方法来实现。首先,你需要在Text组件插入文本,然后使用tag_add()方法给要添加超链接的文本添加一个标签。接下来,使用tag_bind()方法将这个标签与一个回调函数绑定,这个回调函数会在用户点击超链接时被调用。在回调函数,你可以执行相应的操作,比如打开一个网页。 下面是一个示例代码,演示了如何在tkinter添加超链接: ```python import tkinter as tk def open_link(event): # 在这个回调函数执行打开链接的操作 print("打开链接") root = tk.Tk() text = tk.Text(root) text.pack() # 在Text组件插入文本 text.insert(tk.END, "Python之tkinter:") text.insert(tk.END, "tkinter带你进入GUI世界", "link") # 给文本添加一个标签 # 给标签添加超链接的样式 text.tag_config("link", foreground="blue", underline=True) # 绑定回调函数到标签 text.tag_bind("link", "<Button-1>", open_link) root.mainloop() ``` 在这个例子,我们在Text组件插入了两段文本,其一段文本被标记为"link",并且绑定了一个回调函数open_link()。当用户点击带有"link"标签的文本时,回调函数open_link()会被调用。你可以在这个回调函数执行你想要的操作,比如打开一个网页。 注意:在示例,回调函数open_link()只是简单地打印了一条消息。你可以根据自己的需求来修改这个函数,例如使用webbrowser模块在浏览器打开链接。
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值