Skip to main content

IXlMergedCells.Add(XlCellRange) Method

Merges cells in the specified cell range and appends the resulting merged range to the end of the collection.

Namespace: DevExpress.Export.Xl

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

NuGet Package: DevExpress.Printing.Core

Declaration

void Add(
    XlCellRange range
)

Parameters

Name Type Description
range XlCellRange

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

Remarks

Take special note that you cannot merge cells in a range that overlaps existing merged cells in a worksheet. In this case, a ArgumentException will be thrown. If your document contains a large number of merged cells, you can accelerate the process of merging cells and consequently document generation by using the Add method overload with the checkOverlap parameter set to false. This disables the internal checking of the intersecting merged cells. But in this case, you may get an invalid document if there are any merged cells that intersect other merged cells.

Example

Note

A complete sample project is available at https://github.com/DevExpress-Examples/excel-export-api-examples

// Merge cells contained in the range A1:E1.
sheet.MergedCells.Add(XlCellRange.FromLTRB(0, 0, 4, 0));

// Merge cells contained in the range A2:A5.
sheet.MergedCells.Add(XlCellRange.FromLTRB(0, 1, 0, 4));

// Merge cells contained in the range B2:E5.
sheet.MergedCells.Add(XlCellRange.FromLTRB(1, 1, 4, 4));
See Also