Merge and Unmerge Cells
Contents
[
Hide
]
Aspose.Cells.GridWeb has a handy utility feature that lets you merge cells into one large cell. This topic describes how to merge cells programmatically.
Merging Cells
Merge multiple cells in a worksheet into a single cell by calling the Cells collection’s Merge method. Specify the range of cells that to be merged when calling the Merge method.
If you merge multiple cells and each cell contains data, only the content of the top left cell in the range is retained after the merge. Data in the other cells is not lost. If you unmerge the cells, each cell recovers its data.
Four cells merged into one
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 reference of the worksheet that is currently active | |
GridWorksheet sheet = GridWeb1.WorkSheets[GridWeb1.ActiveSheetIndex]; | |
// Merging cells starting from the cell with 3rd row and 3rd column. | |
// 2 rows and 2 columns will be merged from the starting cell | |
sheet.Cells.Merge(2, 2, 2, 2); |
Unmerging Cells
To unmerge cells, use the Cells collection’s UnMerge method that takes same parameters as of the Merge method and performs the unmerging of cells.
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 reference of the worksheet that is currently active | |
GridWorksheet sheet = GridWeb1.WorkSheets[GridWeb1.ActiveSheetIndex]; | |
// Unmerging cells starting from the cell with 3rd row and 3rd column. | |
// 2 rows and 2 columns will be unmerged from the starting cell | |
sheet.Cells.UnMerge(2, 2, 2, 2); |