unmerge_cells clears merged_cells list, leaves merged cells

Issue #1199 duplicate
mario mario created an issue

after calling unmerge_cells for all sheets in a loop and trying to load to DataFrame, an error is thrown stating that "AttributeError: 'MergedCell' object has no attribute 'value'"

my code:

    from openpyxl import load_workbook

    workbook = load_workbook(filename=file)

    for sheet in workbook:
        if "INC" in sheet.title or "BAL" in sheet.title or "CAS" in sheet.title:
            for items in sorted(sheet.merged_cells.ranges):
            data = workbook[sheet.title].values
            cols = next(data)[1:]
            data = list(data) # <-------throws here
            idx = [r[0] for r in data]
            data = (islice(r, 1, None) for r in data)
            sheet_df = df(data, index=idx, columns=cols)

Thinking that it might be a in-loop assignment issue, I exchanged "sheet" to "workbook[sheet.title]", but didn`t work.

The "merged_cells" list gets cleared, but the error still appears while trying to convert the generator to a list.

This is ran on Python 3.6 from Anaconda.

Comments (1)

  1. Log in to comment