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

How to: Merge and Split Table Cells

The following example illustrates how to merge and split table cells programmatically.

Merge Cells

To merge cells, use the Table.MergeCells method with the passed cells marking a range to be merged. As a result, all the cells falling to the stated range will be combined into a single cell. The content of all the merged cells will persist.

Document document = server.Document;
Table table = document.Tables.Create(document.Range.Start, 6, 8);
table.BeginUpdate();
table.MergeCells(table[2, 1], table[5, 1]);
table.MergeCells(table[2, 3], table[2, 7]);
table.EndUpdate();

The image below illustrates the result of code execution.

RichEdit_Examples_MergeCells

Split Cells

The following code snippet splits a table cell into three by using the TableCell.Split method.

Document document = server.Document;
Table table = document.Tables.Create(document.Range.Start, 3, 3, AutoFitBehaviorType.FixedColumnWidth, 350);
//split a cell to three: 
table.Cell(2, 1).Split(1, 3);

The result is illustrated below.

RichEdit_Examples_SplitCells