xlwings 链接到 指定sheet 从别的 excel 复制 sheet 到指定 sheet
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)