Please can someone give me an example, how to copy a whole worksheet with styles (from rows and columns) to a second worksheet in the same workbook ? (in a new workbook would also be possible)
Thank you.
P.S.: I tried to do a deepcopy, but that failed on saving changed data cells.
Purpose is: I try to fill some worksheets with my data and the first worksheet is my template.
I was successful in copying the values but only some styles. I am using the latest version of openpyxl, so please no 1.x methods.
Step1: Import the openpyxl library. Step2: Connect/load the Excel file to the program. Step3: Initialize variables with the source sheet name and destination sheet name. Step4: Create two variables to initialize with the total number of rows and columns in the source Excel sheet.
openpyxl has builtin support for the NumPy types float, integer and boolean. DateTimes are supported using the Pandas' Timestamp type.
Version 2.4 will allow you to do this: copy_worksheet
>>> source = wb.active
>>> target = wb.copy_worksheet(source)
For older ones you can probably copy the source code from here
UPDATE: You can't simply graft this code into older versions of the library
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With