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/word-processing-document-api-examples-t418535
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.
Split Cells
The following code snippet splits a table cell into three by using the TableCell.Split method.
Note
A complete sample project is available at https://github.com/DevExpress-Examples/word-processing-document-api-examples-t418535
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.