I'm trying to move multiple worksheets from multiple workbooks to one workbook. I want each worksheet (i.e. their data, everything is hard coded) to be moved to predetermined worksheets (e.g. worksheet 'temp' from workbook1 to be moved to worksheet 'temp' in workbook2). Currently I am able to move a worksheet to a new workbook but it creates a new sheet each time.
So far I have been using openpyxl but I can't figure out how to reference the worksheets by name instead of position
import openpyxl as xl
path1 = 'workbook 1'
path2 = 'workbook 2'
wb1 = xl.load_workbook(filename = path1)
ws1 = wb1.worksheets[0]
wb2 = xl.load_workbook(filename = path2)
ws2 = wb2.get_sheet_name["NAME"]
for row in ws1:
for cell in row:
ws2[cell.coordinate].value=cell.value
wb2.save(path2)
When I try reference the sheet name in wb2 is where the code breaks down. I'm sure there's an easy fix to this but I can't seem to work it out