简体   繁体   中英

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)
unmerge_cells(range_string=None, start_row=None, start_column=None, end_row=None, end_column=None) 

range_string is a cell range (eg A1:E1)

You need to pass the range as a string.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM