[英]How to use hyperlink in excel to link to another worksheet cell in same workbook in python
How to link to antother worksheet in same workbook in excel如何链接到Excel中同一工作簿中的另一个工作表
this python script is not这个python脚本不是
from openpyxl import load_workbook
wb = load_workbook("excel_hyper_link_test.xlsx")
ws = wb.get_sheet_by_name("Sheet1")
link = "excel_hyper_link_test.xlsx#Sheet2!E5"
print ws.cell(row=1, column=1).value
ws.cell(row=1, column=1).hyperlink = (link)
After running this script i opened excel sheet and i could not see any hyperlink运行此脚本后,我打开了 excel 表,但看不到任何超链接
note: I am using linux platform注意:我使用的是 linux 平台
This worked for me这对我有用
from openpyxl import load_workbook
xlsFile='excel_hyper_link_test.xlsx'
wbook = load_workbook(xlsFile)
wsheet1= wbook.get_sheet_by_name('Sheet1')
cell1 = wsheet1.cell('A1')
cell1.hyperlink = '#Sheet2!E5'
cell1.value=r'XXX'
wbook.save(xlsFile)
import pandas as pd
import openpyxl as opxl
def hyperlinking(New_file_path):
xls = pd.ExcelFile(New_file_path)
sheets = xls.sheet_names # Get the worksheet names
wb = opxl.load_workbook(New_file_path)
ws = wb.create_sheet("Consolitated_Sheet") # Create a New worksheet
ws['A1'] = "Sheet_Name"; ws['B1'] = "Active_link" #New sheet we are proving column names
for i, j in enumerate(sheets):
# print('A'+str(i+2) + ' value is: ' + j)
ws['A' + str(i + 2)] = j # As A1 cell is occupied with column name we are taking reference of second row(A2).
ws['B' + str(i + 2)].value = '=HYPERLINK("%s", "%s")' % ('#' + str(j) + '!A1', 'Clickhere') # For A2 cell value we are providing hyperlinks of respective sheet
wb.save(New_file_path)
wb.close()
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.