unmerge_cells Exception

Skip to first unread message

Ago ni

Mar 20, 2024, 3:21:50 AMMar 20
to openpyxl-users
Hey, guys.

I unmerge cells in the following way.

merged_cells = ws.merged_cells
for m_area in merged_cells:
    r1, r2, c1, c2 = m_area.min_row, m_area.max_row, m_area.min_col, m_area.max_col
    if r2 - r1 > 0:
       ws.unmerge_cells(start_row=r1, end_row=r2, start_column=c1, end_column=c2)
return ws

It works fine in version 3.0.10. But the latest 3.1.2. throws an exception.

  File "/home/xxxxxx/miniconda3/lib/python3.9/site-packages/openpyxl/worksheet/cell_range.py", line 506, in __iter__
    for cr in self.ranges:
        │     │    └ {<MergedCellRange D106:D108>, <MergedCellRange C5:C8>, <MergedCellRange D147:D151>, <MergedCellRange D99:D100>, <MergedCellRa...
        │     └ <MultiCellRange [A3:A186 B4:B100 B101:B113 B114:B186 C5:C8 C9:C97 C98:C100 C102:C104 C105:C108 C109:C113 C115:C119 C120:C151 ...
        └ <MergedCellRange C180:C186>
RuntimeError: Set changed size during iteration

Is there some kind of disruptive change?
Reply all
Reply to author
0 new messages