Merge Cells

GemBox.Document supports merged cells in the same way as HTML - every table cell contains RowSpan and ColumnSpan properties.

Following example demonstrates how to create a table with merged cells (RowSpan and / or ColumnSpan greater than 1).

Screenshot
Merge Cells Screenshot

See the full code below, use Run Example to execute.

using System;
using System.Data;
using GemBox.Document;
using GemBox.Document.Tables;

class Sample
{
    [STAThread]
    static void Main(string[] args)
    {
        // If using Professional version, put your serial key below.
        ComponentInfo.SetLicense("FREE-LIMITED-KEY");

        DocumentModel document = new DocumentModel();

        Table table = new Table(document,
            new TableRow(document,
                new TableCell(document, new Paragraph(document, "Cell 1-1")),
                new TableCell(document, new Paragraph(document, "Cell 1-2")),
                new TableCell(document, new Paragraph(document, "Cell 1-3")),
                new TableCell(document, new Paragraph(document, "Cell 1-4"))),
            new TableRow(document,
                new TableCell(document, new Paragraph(document, "Cell 2-1")),
                new TableCell(document, new Paragraph(document, "Cell 2-2 -> 2-4"))
                {
                    ColumnSpan = 3
                }),
            new TableRow(document,
                new TableCell(document, new Paragraph(document, "Cell 3-1")),
                new TableCell(document, new Paragraph(document, "Cell 3-2 -> 5-3"))
                {
                    ColumnSpan = 2,
                    RowSpan = 3
                },
                new TableCell(document, new Paragraph(document, "Cell 3-4 -> 5-4"))
                {
                    RowSpan = 3
                }),
            new TableRow(document,
                new TableCell(document, new Paragraph(document, "Cell 4-1"))),
            new TableRow(document,
                new TableCell(document, new Paragraph(document, "Cell 5-1"))));

        table.TableFormat.DefaultCellPadding = new Padding(10, 4);
        table.TableFormat.PreferredWidth = new TableWidth(350, TableWidthUnit.Point);

        document.Sections.Add(new Section(document, table));

        document.Save("Merge Cells.docx");
    }
}
Imports System
Imports System.Data
Imports GemBox.Document
Imports GemBox.Document.Tables

Module Samples

    Sub Main()

        ' If using Professional version, put your serial key below.
        ComponentInfo.SetLicense("FREE-LIMITED-KEY")

        Dim document As DocumentModel = New DocumentModel

        Dim table As New Table(document,
                            New TableRow(document,
                                New TableCell(document,
                                    New Paragraph(document, "Cell 1-1")),
                                New TableCell(document,
                                    New Paragraph(document, "Cell 1-2")),
                                New TableCell(document,
                                    New Paragraph(document, "Cell 1-3")),
                                New TableCell(document,
                                    New Paragraph(document, "Cell 1-4"))),
                            New TableRow(document,
                                New TableCell(document,
                                    New Paragraph(document, "Cell 2-1")),
                                New TableCell(document,
                                    New Paragraph(document, "Cell 2-2 -> 2-4")) With {
                                     .ColumnSpan = 3
                                    }),
                            New TableRow(document,
                                New TableCell(document,
                                    New Paragraph(document, "Cell 3-1")),
                                New TableCell(document,
                                    New Paragraph(document, "Cell 3-2 -> 5-3")) With {
                                     .ColumnSpan = 2,
                                     .RowSpan = 3
                                    },
                                New TableCell(document,
                                    New Paragraph(document, "Cell 3-4 -> 5-4")) With {
                                     .RowSpan = 3
                                    }),
                            New TableRow(document,
                                New TableCell(document,
                                    New Paragraph(document, "Cell 4-1"))),
                            New TableRow(document,
                                New TableCell(document,
                                    New Paragraph(document, "Cell 5-1"))))

        table.TableFormat.DefaultCellPadding = New Padding(10, 4)
        table.TableFormat.PreferredWidth = New TableWidth(350, TableWidthUnit.Point)

        document.Sections.Add(New Section(document, table))

        document.Save("Merge Cells.docx")

    End Sub

End Module