krakowi
krakowi

Reputation: 613

How to unmerge cells in excel worksheet?

I have a class that represents a worksheet in Excel. I would like to get rid of all merged cells using unmerge_cells function. When I am running the code I can see (comparing to my excel worksheet) that all ranges from the list are passed correctly, but the range does not seem to be unmerged.. None of ranges have been unmerged.. What am I overseeing?

from openpyxl.utils import *


class ExcelSheet(object):
    """

    This class represents excel worksheet.
    Attributes:

        sheet_obj - excel worksheet object
        self.merged_cells_ranges - list of ranges with merged cells

    """
    def __init__(self, sheet_obj):
        self.sheet_obj = sheet_obj
        self.merged_cells_ranges = self.sheet_obj.merged_cell_ranges


    def unmerge_cells(self):
        if len(self.merged_cells_ranges) > 0:
            for range in self.merged_cells_ranges:
                self.sheet_obj.unmerge_cells(range)

Upvotes: 3

Views: 3331

Answers (1)

ConSod
ConSod

Reputation: 801

unmerge_cells(range_string=None, start_row=None, start_column=None, end_row=None, end_column=None) 

range_string is a cell range (e.g. A1:E1)

You need to pass the range as a string.

Upvotes: 1

Related Questions