TypeError when trying to copy a worksheet with a merged cell

Issue #1058 resolved
Liam Sanders created an issue

Fairly easy to reproduce, create a new workbook (or see attached) and merge a few cells then run the following code:

from openpyxl import load_workbook

wb = load_workbook("test.xlsx")
ws = wb["Sheet1"]
ws2 = wb.copy_worksheet(ws)

This gives the following error.

Traceback (most recent call last):
  File "copy_ws.py", line 5, in <module>
    ws2 = wb.copy_worksheet(ws)
  File "C:\Python\Python36-32\lib\site-packages\openpyxl\workbook\workbook.py", line 394, in copy_worksheet
  File "C:\Python\Python36-32\lib\site-packages\openpyxl\worksheet\copier.py", line 43, in copy_worksheet
    self.target.merged_cells = copy(self.source.merged_cells)
  File "C:\Python\Python36-32\lib\copy.py", line 88, in copy
    return copier(x)
  File "C:\Python\Python36-32\lib\site-packages\openpyxl\worksheet\cell_range.py", line 456, in __copy__
  File "C:\Python\Python36-32\lib\copy.py", line 88, in copy
    return copier(x)
  File "C:\Python\Python36-32\lib\site-packages\openpyxl\worksheet\cell_range.py", line 136, in __copy__
TypeError: __init__() got an unexpected keyword argument 'min_col'

Comments (5)

  1. CharlieC

    Thanks for the report, looks like the MergeCell needs its own copy method implementation because we only ever work with the string version.

  2. Log in to comment