Copy pasting multiple sheets into new workbook

前端 未结 1 1395
别跟我提以往
别跟我提以往 2021-01-27 07:54

The goal is to copy paste multiple existing sheets out of a workbook into a new workbook using xlwings. I have:

app = xw.App(visible=False)
book = xw.Book(path)
         


        
相关标签:
1条回答
  • 2021-01-27 08:43

    If you can use win32com, you can try this:

    from win32com.client import Dispatch
    
    path1 = 'workbook1.xlsx'
    path2 = 'workbook2.xlsx'
    
    xl = Dispatch("Excel.Application")
    
    wb1 = xl.Workbooks.Open(Filename=path1)
    wb2 = xl.Workbooks.Open(Filename=path2)
    
    ws1 = wb1.Worksheets(1)
    ws1.Copy(Before=wb2.Worksheets(1))
    
    wb2.Close(SaveChanges=True)
    xl.Quit()
    
    0 讨论(0)
提交回复
热议问题