GemBox.Document is a .NET component that enables you to read, write, edit, convert, and print document files from your .NET applications using one simple API.

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

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

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

class Sample
    static void Main(string[] args)
        // If using Professional version, put your serial key below.

        DocumentModel document = new DocumentModel();

        int tableRowCount = 10;
        int tableColumnCount = 5;

        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.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.

        Dim document As DocumentModel = New DocumentModel

        Dim tableRowCount As Integer = 10
        Dim tableColumnCount As Integer = 5

        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.docx")

    End Sub

End Module

Check next sample.