from openpyxl import load_workbook
# 加载现有的工作簿
from openpyxl.utils import get_column_letter
wb = load_workbook("C:\\Users\\CMS01\\Desktop\\SCHH621TEG_LDO(PLDO、NLDO、CPLDO)测试需求_20230814.xlsx")
# 获取Sheet1和Sheet6
sheet1 = wb['Sheet7']
sheet6 = wb['Sheet6']
cell_positions = []
for column in range(2, 323, 4):
column_letter = get_column_letter(column) # 将列号转换为字母表示的列名
cell_positions.append(f"{column_letter}5")
print(f"{column_letter}5") # B5 F5 J5 N5 ...
# 在Sheet1中创建超链接到Sheet6中指定单元格的值
column_index = 1 # 开始填充链接的列索引(从1开始)
for row_index, cell_position in enumerate(cell_positions, start=1):
link_formula = f'=HYPERLINK("#\'Sheet6\'!{cell_position}","\'Sheet6\'!{cell_position}")'
sheet1.cell(row=row_index, column=column_index).value = link_formula
# 保存工作簿
wb.save("C:\\Users\\CMS01\\Desktop\\SCHH621TEG_LDO(PLDO、NLDO、CPLDO)测试需求_20230814.xlsx")
标签:index,wb,Python,单元格,excel,cell,column,Sheet6,letter
From: https://www.cnblogs.com/cloud-sword/p/17685672.html