How to copy over an Excel sheet to another workbook in Python

后端 未结 4 1589
醉话见心
醉话见心 2020-11-27 16:41

I have a string with a sourcefile path and another string with a destfile path, both pointing to Excel workbooks.

I want to take the first sheet of the sourcefile an

4条回答
  •  生来不讨喜
    2020-11-27 17:38

    Long battle and finally got the answer. From xlwings source code: https://github.com/xlwings/xlwings/pull/1216/files

    source_sheet.range.copy(destination_sheet.range)
    

    In other words:

    wb.sheets['Sheet1'].range('A1:A6').copy(wb.sheets['Sheet2'].range('A1:A6'))
    
    • It works also from one workbook to another workbook.
    • A range of cells must be provided. Just ensure the range is big enough to cover the full worksheet.
    • The copy function copy/paste everything withing a range of cells (values, cell format, hyperlinks, cell type, ...)

提交回复
热议问题