Attempts to find and unmerge all merged cells in excel worksheet fails

Issue #576 invalid
Gathua Phone created an issue

On a worksheet that has several merged cells that are not continous, I am using the code ws.unmerge_cells('A1:Q2000') this covers all the data in the worksheet merged and unmerged. This fails with the message: InsufficientCoordinatesException: Cell range A1:Q2000 not known as merged.

Comments (9)

  1. Gathua Phone reporter

    Hi Mr. Clark, thank you for responding to my issue. Please find attached a sample file. The full code I tried to use was as below:
    from openpyxl import load_workbook
    myfile = 'D:/Downloads/02-Sep-2015.xlsx'
    wb = load_workbook(filename = myfile)
    ws =

  2. Gathua Phone reporter

    Ok, If I understand, I would need to find the merged cells ranges one by one, select them and unmerge them. If I select all the used cells and simply request to unmerge, it will not work?

  3. Gathua Phone reporter

    Ended up using the merged_cell_ranges () :-)

    myfile = 'D:/Downloads/01-Sep-2015.xlsx'
    from openpyxl import load_workbook
    wb = load_workbook(filename = myfile)
    sheet = wb.get_active_sheet()
    for items in sorted(sheet.merged_cell_ranges):
        sheet.unmerge_cells(str(items) )
  4. Log in to comment