Skip to main content
Row

Worksheet.MergeCells(CellRange) Method

Merges the specified cells.

Namespace: DevExpress.Spreadsheet

Assembly: DevExpress.Spreadsheet.v24.1.Core.dll

NuGet Package: DevExpress.Spreadsheet.Core

Declaration

void MergeCells(
    CellRange range
)

Parameters

Name Type Description
range CellRange

A CellRange object that specifies a range of cells to be merged.

Remarks

To access a cell obtained as a result of merging a cell range, use a cell reference for the top left cell of the original range or a reference for any range with this top left cell within the original range.

SpreadsheetControl_MergeCells

To unmerge cells, use the Worksheet.UnMergeCells method.

Another way to merge and unmerge a cell range is to use the range’s RangeExtensions.Merge and RangeExtensions.UnMerge extension methods, defined by the RangeExtensions class. These extension methods are accessible as methods of the CellRange object and called by using the instance method syntax.

Example

This example demonstrates how to merge several cells into a single cell. To do this, use the Worksheet.MergeCells method with the passed range of cells to be merged.

Note

When you merge a cell range, the data (value, formula and format settings) of only the top left non-empty cell will appear in the resulting merged cell. The data contained in other cells of the original range will be lost.

If all cells within the original range are empty, the range’s top left cell format will be applied to the merged cell.

View Example

// Merge cells contained in the range.
worksheet.MergeCells(worksheet.Range["A1:C5"]);

The following code snippets (auto-collected from DevExpress Examples) contain references to the MergeCells(CellRange) method.

Note

The algorithm used to collect these code examples remains a work in progress. Accordingly, the links and snippets below may produce inaccurate results. If you encounter an issue with code examples below, please use the feedback form on this page to report the issue.

See Also