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.

NOTE

A complete sample project is available at https://github.com/DevExpress-Examples/wpf-richedit-document-api-t213968.

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

Use the TableCell.Split method to split a cell into the required number of rows and columns.

NOTE

A complete sample project is available at https://github.com/DevExpress-Examples/wpf-richedit-document-api-t213968.

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