1

I'm useing xlwings on a Windows.

I copy a worksheet and want to reproduce it at the end of an existing worksheet now. In a worksheet to copy, I use a photograph and the figure.

I know some sample code to reproduce copy a worksheet.

I would appreciate it if you could answer my questions.

rja7218
  • 25
  • 1
  • 9
  • What do you mean by "reprint"? – Felix Zumstein Jul 24 '16 at 20:39
  • Thank you for your comment.I understood a word by mistake.I revised a question.I know some sample code to reproduce copy a worksheet. – rja7218 Jul 26 '16 at 04:35
  • This is not natively available yet, but you can work around like described here: https://github.com/ZoomerAnalytics/xlwings/issues/123 – Felix Zumstein Jul 26 '16 at 06:20
  • I'm Sorry,there was the same question.I have read your put link.I need After keyword so I have to wait until it's implemented.Thank you for telling me. – rja7218 Jul 26 '16 at 15:58
  • As written in the answer, the `After` parameter is implemented, it's just a little different to write. For example, `sheet.api.Copy(None, After=existingSheet.api)`. See [here](https://stackoverflow.com/questions/56687602/copy-excel-sheet-from-one-worksheet-to-another-in-python). – mouwsy Dec 23 '20 at 21:18

3 Answers3

3

The correct answer to copy a worksheet to the end of a workbook is to use the After parameter.

import xlwings as xw

wb = xw.Book("test.xlsx")
ws1 = wb.sheets['Sheet1']

ws1.api.Copy(None, After=wb.sheets[-1].api)

Update 18. November 2021:

Since xlwings version 0.22 you can use the built-in .copy():

import xlwings as xw

wb = xw.Book("test.xlsx")
ws1 = wb.sheets['Sheet1']

ws1.copy(name="name_of_copied_sheet")
mouwsy
  • 1,457
  • 12
  • 20
0

I was settled with this code:

Sheet(1).xl_sheet.Copy(Before=Sheet(1).xl_sheet) 
rja7218
  • 25
  • 1
  • 9
0

Starting from v0.10.4 replace xl_sheet with api:

Sheet(1).api.Copy(Before=Sheet(1).api)
Robert
  • 1,357
  • 15
  • 26