xlwings 链接到 指定sheet 从别的 excel 复制 sheet 到指定 sheet
重点
(图片来源网络,侵删)
可以参考 宏录制
cell = sheet.range('G4') cell.api.Hyperlinks.Add(Anchor=cell.api, Address="", SubAddress="'001-000-023+01'!A1")
def deal_excel(self): with xw.App(visible=True) as app: wb = app.books.open(self.summary_path, update_links=False) sheet = wb.sheets[0] for pn in self.pn_list: pn_path = os.path.join(cuixiao_data_raw, f'{pn}.xlsx') wb_pn = app.books.open(pn_path, update_links=False) sheet_pn = wb_pn.sheets[0] new_sheet = sheet_pn.copy(after=wb.sheets[0]) new_sheet.name = pn for i in range(4, 99999): if sheet.range(f'G{i}').value: cell = sheet.range(f'G{i}') value = cell.value print('value', i, value) cell.api.Hyperlinks.Add(Anchor=cell.api, Address="", SubAddress=f"'{value}'!A1") else: break # cell = sheet.range('G4') # cell.api.Hyperlinks.Add(Anchor=cell.api, Address="", SubAddress="'001-000-023+01'!A1") sheet.name = 'Summary' sheet.range('A1').value = '' sheet.activate() # 激活指定的工作表 sheet.range('A1').select() # 选择特定的单元格 result_path = os.path.join(cuixiao_data_result, f'{today}_result.xlsx') wb.save(result_path)
参考
https://blog.csdn.net/xcntime/article/details/115640772
文章版权声明:除非注明,否则均为主机测评原创文章,转载或复制请以超链接形式并注明出处。