Merge and Unmerge Cells in GridDesktop
Contents
[
Hide
]
In this topic, we will discuss a utility feature of merge and unmerge cells of a worksheet. This feature is useful in those cases when we need to span some rows or columns to enhance the readability of data.
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.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// 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.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// 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); |
When you merge cells into a single cell then the formatting settings of top left cell (in the range of cells) are applied on the merged cell but when the cell is unmerged, all unmerged cells maintain their formatting settings.