Merge and Unmerge Cells in GridDesktop

Merge Cells

To merge cells into a single large cell, please follow the steps below:

  • Access any desired Worksheet
  • Create a Range of Cells to be merged
  • Merge the range of cells into a large cell

You can use Merge method of Worksheet to merge cells. However, a range of cells can be defined using CellRange object.

// For complete examples and data files, please go to https://github.com/aspose-cells/Aspose.Cells-for-.NET
// Accessing the worksheet of the Grid that is currently active
Worksheet sheet = gridDesktop1.GetActiveWorksheet();
// Creating a CellRange object starting from "B4" to "C6"
CellRange range = new CellRange("B4", "C6");
// Merging a range of cells
sheet.Merge(range);

Unmerge Cells

To unmerge a large cell into many cells, please follow the steps below:

  • Access any desired Worksheet
  • Access the merged cell that needs to be unmerged
  • Unmerge the large cell into many cells using the location of merged cell

You can use Unmerge method of Worksheet to unmerge a cell using its location.

// For complete examples and data files, please go to https://github.com/aspose-cells/Aspose.Cells-for-.NET
// Accessing the worksheet of the Grid that is currently active
Worksheet sheet = gridDesktop1.GetActiveWorksheet();
// Accessing the merged cell that is currently in focus
GridCell cell = sheet.GetFocusedCell();
// Unmerging a cell using its location
sheet.Unmerge(cell.Location);