Good job! Suppose you need several very similar worksheets in your workbook. Instead of making each one from scratch, you can copy an existing worksheet:
ws = wb.active
wb_copy = worksheet(ws)
The new sheet will appear in your workbook under the name of the worksheet you copied and the word
"Copy". If we had a
"Calendar" worksheet and we copied it, the new sheet's name would be
"Calendar Copy". However, you need to remember that:
- You cannot copy worksheets from different workbooks.
- In the current version of
openpyxl, it is not possible to copy elements like charts or images.
To be safe, use
copy_worksheet to copy cell data you want to preserve.