Simple Table

Tables are used to present content in a rectangular grid. Tables, along with other content such as charts or SmartArt diagrams, are embedded in a special kind of drawing, called a graphic frame, which is contained on the slide surface.

In the GemBox.Presentation API, the table-related types are grouped in the GemBox.Presentation.Tables namespace.

The following example shows how to create and populate a simple table using the GemBox.Presentation API.

Screenshot of PowerPoint table created with GemBox.Presentation
PowerPoint table created with GemBox.Presentation
using GemBox.Presentation;
using GemBox.Presentation.Tables;

class Program
{
    static void Main()
    {
        // If using Professional version, put your serial key below.
        ComponentInfo.SetLicense("FREE-LIMITED-KEY");

        var presentation = new PresentationDocument();

        // Create new presentation slide.
        var slide = presentation.Slides.AddNew(SlideLayoutType.Custom);

        // Create new table.
        var table = slide.Content.AddTable(5, 5, 20, 12, LengthUnit.Centimeter);

        // Format table with no-style grid.
        table.Format.Style = presentation.TableStyles.GetOrAdd(
            TableStyleName.NoStyleTableGrid);

        int columnCount = 4;
        int rowCount = 10;

        for (int i = 0; i < columnCount; i++)
            // Create new table column.
            table.Columns.AddNew(Length.From(5, LengthUnit.Centimeter));

        for (int i = 0; i < rowCount; i++)
        {
            // Create new table row.
            var row = table.Rows.AddNew(
                Length.From(1.2, LengthUnit.Centimeter));

            for (int j = 0; j < columnCount; j++)
            {
                // Create new table cell.
                var cell = row.Cells.AddNew();

                // Set table cell text.
                cell.Text.AddParagraph().AddRun(
                    string.Format(null, "Cell {0}-{1}", i + 1, j + 1));
            }
        }

        presentation.Save("Simple Table.%OutputFileType%");
    }
}
Imports GemBox.Presentation
Imports GemBox.Presentation.Tables

Module Program

    Sub Main()

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

        Dim presentation = New PresentationDocument

        ' Create new presentation slide.
        Dim slide = presentation.Slides.AddNew(SlideLayoutType.Custom)

        ' Create new table.
        Dim table = slide.Content.AddTable(5, 5, 20, 12, LengthUnit.Centimeter)

        ' Format table with no-style grid.
        table.Format.Style = presentation.TableStyles.GetOrAdd(
            TableStyleName.NoStyleTableGrid)

        Dim columnCount As Integer = 4
        Dim rowCount As Integer = 10

        For i As Integer = 0 To columnCount - 1
            ' Create new table column.
            table.Columns.AddNew(Length.From(5, LengthUnit.Centimeter))
        Next

        For i As Integer = 0 To rowCount - 1

            ' Create new table row.
            Dim row = table.Rows.AddNew(
                Length.From(1.2, LengthUnit.Centimeter))

            For j As Integer = 0 To columnCount - 1

                ' Create new table cell.
                Dim cell = row.Cells.AddNew()

                ' Set table cell text.
                cell.Text.AddParagraph().AddRun(
                    String.Format(Nothing, "Cell {0}-{1}", i + 1, j + 1))
            Next
        Next

        presentation.Save("Simple Table.%OutputFileType%")
    End Sub
End Module

Check next example or download examples from GitHub.