Merge cells after copying a worksheet change original worksheet.

Issue #970 resolved
Andrew Nikolayenkov created an issue

A small example:

from openpyxl import Workbook
wb = Workbook()
ws1 =
ws2 = wb.copy_worksheet(ws1)

In the file, you can see that the cells are merged in both sheets - ws1 and w2.

Comments (5)

  1. Andrew Nikolayenkov reporter

    I think the problem can be solved by replacing (line 43) with the 'copy' function with 'deepcopy'. = deepcopy (self.source.merged_cells)

    Please confirm that this is the right decision!

  2. CharlieC

    Not really. deepcopy can cause problems when used indiscriminately. Better to write a dedicated __copy__ method for the relevant object to make sure you get the kind of copy (deep or shallow) you want. Easier to test and more reliable.

  3. Andrew Nikolayenkov reporter

    As a temporary solution to this problem, I will use deepcopy in my project. And in the next versions of the library, you will correct this error in the correct way!

    Thank you so much for your work! Very convenient library !!!

  4. Log in to comment