Back to Devexpress

Table.MergeCells(TableCell, TableCell) Method

officefileapi-devexpress-dot-docs-dot-presentation-dot-table-dot-mergecells-x28-devexpress-dot-docs-dot-presentation-dot-tablecell-devexpress-dot-docs-dot-presentation-dot-tablecell-x29.md

latest4.0 KB
Original Source

Table.MergeCells(TableCell, TableCell) Method

Merges two adjacent table cells into one cell.

Namespace : DevExpress.Docs.Presentation

Assembly : DevExpress.Docs.Presentation.v25.2.dll

NuGet Package : DevExpress.Docs.Presentation

Declaration

csharp
public void MergeCells(
    TableCell tableCell1,
    TableCell tableCell2
)
vb
Public Sub MergeCells(
    tableCell1 As TableCell,
    tableCell2 As TableCell
)

Parameters

NameTypeDescription
tableCell1TableCell

The first table cell to merge.

| | tableCell2 | TableCell |

The second table cell to merge.

|

Remarks

Call the Table.MergeCells method to merge a rectangular range of table cells. The first cell in the method parameters specifies the start of the range, and the second specifies the end of the range. After the cells are merged, the Presentation API performs the following steps:

  • The first cell’s ColumnSpan or RowSpan property is increased by the corresponding number of columns or rows.
  • Text paragraphs of merged cells are appended to the first cell Paragraphs collection.
  • The TextArea property of merged cells is set to null.
  • The merged cells’ TableCell.IsMergedVertically or TableCell.IsMergedHorizontally property is set to true depending on the position of merged cells.

The following code snippet merges two cells in a table:

csharp
using DevExpress.Docs.Presentation;

namespace PresentationApiSample;

public class Program {
    public static void Main(string[] _) {
        //...

        // Create a 3x3 table (rows x columns) and add it as a shape to the slide
        Table table = new Table(3, 3);
        slide.Shapes.Add(table);

        for (int row = 0; row < 3; row++) {
            for (int column = 0; column < 3; column++) {
                table[row, column].TextArea.Text = $"({row}, {column})";
            }
        }

        table.MergeCells(table[0, 0], table[0, 1]);

    }
}
vb
Imports DevExpress.Docs.Presentation

Namespace PresentationApiSample

    Public Class Program
        Public Shared Sub Main(__ As String())
            '...

            ' Create a 3x3 table (rows x columns) and add it as a shape to the slide
            Dim table As Table = New Table(3, 3)
            slide.Shapes.Add(table)

            For row As Integer = 0 To 2
                For column As Integer = 0 To 2
                    table(row, column).TextArea.Text = $"({row}, {column})"
                Next
            Next

            table.MergeCells(table(0, 0), table(0, 1))

        End Sub
    End Class
End Namespace

See Also

Table Class

Table Members

DevExpress.Docs.Presentation Namespace