Merge or Unmerge Range of Cells

Possible Usage Scenarios

You can use Aspose.Cells for Python via .NET to merge or split a range of cells. Aspose.Cells for Python via .NET provides the Range.merge() and Range.un_merge() methods for this purpose. This article explains how to merge a range of cells into a single cell.

How to Merge or Unmerge Range of Cells

The following sample code first creates a range - A1:D4 - then merges the cells in the range into a single cell using the Range.merge() method. Similarly, you can split cells by creating a range and calling the Range.un_merge() method.

from aspose.cells import Workbook
# For complete examples and data files, please go to https:# github.com/aspose-cells/Aspose.Cells-for-.NET
# The path to the documents directory.
dataDir = RunExamples.GetDataDir(".")
# Create a workbook
workbook = Workbook()
# Access the first worksheet
worksheet = workbook.worksheets[0]
# Create a range
range = worksheet.cells.create_range("A1:D4")
# Merge range into a single cell
range.merge()
# Save the workbook
workbook.save(dataDir + "output.out.xlsx")