How to: Merge Cells or Split Merged Cells

  • 2 minutes to read
  • Merge Cells

    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.


    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.
  • Split Merged Cells

    Call the Worksheet.UnMergeCells method with the passed range that contains merged cells to be split. Note that the content and formatting that were set in cells before merging will be lost (with the exception of the top left cell).

    // Split cells that were previously merged.
  • Split All Merged Cells in a Worksheet

    To get all merged cells in the specified cell range, use the CellRange.GetMergedRanges method.

    // Split all merged cells in the worksheet.
    foreach (var item in worksheet.Cells.GetMergedRanges()) {

The image below shows how cells are merged and split in a worksheet (the workbook is opened in SpreadsheetControl). Note that only the “B2” data (the top left non-empty cell) appears in the merged cell.