Skip to main content
A newer version of this page is available. .

How to: Merge Cells or Split Merged 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.

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.

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