Simple Table

Tables are used to organize document content in rows and columns. In GemBox.Document, table related types are contained in a separate GemBox.Document.Tables namespace.

Following example demonstrates how to create and populate a simple table by constructing all table related elements – table, table rows and table cells.

Simple Table Screenshot
using GemBox.Document;
using GemBox.Document.Tables;

class Program
    static void Main()
        // If using Professional version, put your serial key below.

        DocumentModel document = new DocumentModel();

        int tableRowCount = %RowCount%;
        int tableColumnCount = %ColumnCount%;

        Table table = new Table(document);
        table.TableFormat.PreferredWidth = new TableWidth(100, TableWidthUnit.Percentage);

        for (int i = 0; i < tableRowCount; i++)
            TableRow row = new TableRow(document);

            for (int j = 0; j < tableColumnCount; j++)
                Paragraph para = new Paragraph(document, string.Format("Cell {0}-{1}", i + 1, j + 1));

                row.Cells.Add(new TableCell(document, para));

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

        document.Save("Simple Table.%OutputFileType%");
Imports GemBox.Document
Imports GemBox.Document.Tables

Module Program

    Sub Main()

        ' If using Professional version, put your serial key below.

        Dim document As DocumentModel = New DocumentModel

        Dim tableRowCount As Integer = %RowCount%
        Dim tableColumnCount As Integer = %ColumnCount%

        Dim table As New Table(document)
        table.TableFormat.PreferredWidth = New TableWidth(100, TableWidthUnit.Percentage)

        For i As Integer = 0 To tableRowCount - 1
            Dim row As New TableRow(document)

            For j As Integer = 0 To tableColumnCount - 1
                Dim para As New Paragraph(document, String.Format("Cell {0}-{1}", i + 1, j + 1))

                row.Cells.Add(New TableCell(document, para))

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

        document.Save("Simple Table.%OutputFileType%")

    End Sub

End Module

Check next example or download examples from GitHub.