简体   繁体   English

如何使用excel中的超链接链接到python中同一工作簿中的另一个工作表单元格

[英]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.

相关问题 如何使用python将Excel工作表复制到具有相同格式的另一个工作簿 - How to copy excel sheet to another workbook with same format using python 如何在同一工作簿中使用python将数据从一个工作表传输到另一个工作表? - How to transfer data from one worksheet into another using python in the same workbook? 如何在同一工作簿中创建指向不同 Excel 工作表的超链接 - How to create a hyperlink to a different Excel sheet in the same workbook 如何使用Python xlwings在excel工作簿中检测受保护的工作表? - How to detect protected worksheet in excel workbook using Python xlwings? Python/Openpyxl:将工作簿中所有 excel 工作表中的单元格 A1 更改为等于工作表选项卡的名称 - Python/Openpyxl: change cell A1 in all excel worksheets within a workbook to equal the name of the worksheet tab 如何使用 Python 将数据从一个 Excel 工作表复制到同一工作簿的另一工作表? - How to copy data from One Excel sheet to another sheet for same Workbook Using Python? 如何使用python从Excel工作表中提取超链接单元格 - How to extract the hyperlink cell from excel sheet using python 将受保护的Excel工作簿复制到另一个工作簿python中 - Copy Protected excel workbook into another workbook python 使用python使用excel工作表(具有所需条件)创建excel工作簿 - Creating excel workbook using excel worksheet (with required condition) using python 使用 Python 打开 Excel 工作簿 - Use Python to open an Excel workbook
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM