Table Formatting

In GemBox.Presentation, table-formatting options can be specified for a table and table cells.

The following example shows how you can create a formatted table.

PowerPoint table formatted with GemBox.Presentation
Screenshot of PowerPoint table formatted 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, 5, LengthUnit.Centimeter);

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

        table.Format.Fill.SetSolid(Color.FromName(ColorName.Orange));

        table.Columns.AddNew(Length.From(7, LengthUnit.Centimeter));
        table.Columns.AddNew(Length.From(10, LengthUnit.Centimeter));
        table.Columns.AddNew(Length.From(5, LengthUnit.Centimeter));

        var row = table.Rows.AddNew(Length.From(5, LengthUnit.Centimeter));

        var cell = row.Cells.AddNew();

        cell.Format.Fill.SetSolid(Color.FromName(ColorName.Red));

        cell.Text.Format.VerticalAlignment = VerticalAlignment.Top;

        cell.Text.AddParagraph().AddRun("Cell 1-1");

        cell = row.Cells.AddNew();

        var border = cell.Format.DiagonalDownBorderLine;

        border.Fill.SetSolid(Color.FromName(ColorName.White));
        border.Width = Length.From(5, LengthUnit.Millimeter);

        border = cell.Format.DiagonalUpBorderLine;

        border.Fill.SetSolid(Color.FromName(ColorName.White));
        border.Width = Length.From(5, LengthUnit.Millimeter);

        cell.Text.Format.VerticalAlignment = VerticalAlignment.Middle;

        cell.Text.AddParagraph().AddRun("Cell 1-2");

        cell = row.Cells.AddNew();

        cell.Format.Fill.SetSolid(Color.FromName(ColorName.DarkBlue));

        cell.Text.Format.VerticalAlignment = VerticalAlignment.Bottom;

        cell.Text.AddParagraph().AddRun("Cell 1-3");

        presentation.Save("Table Formatting.%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, 5, LengthUnit.Centimeter)

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

        table.Format.Fill.SetSolid(Color.FromName(ColorName.Orange))

        table.Columns.AddNew(Length.From(7, LengthUnit.Centimeter))
        table.Columns.AddNew(Length.From(10, LengthUnit.Centimeter))
        table.Columns.AddNew(Length.From(5, LengthUnit.Centimeter))

        Dim row = table.Rows.AddNew(Length.From(5, LengthUnit.Centimeter))

        Dim cell = row.Cells.AddNew()

        cell.Format.Fill.SetSolid(Color.FromName(ColorName.Red))

        cell.Text.Format.VerticalAlignment = VerticalAlignment.Top

        cell.Text.AddParagraph().AddRun("Cell 1-1")

        cell = row.Cells.AddNew()

        Dim border = cell.Format.DiagonalDownBorderLine

        border.Fill.SetSolid(Color.FromName(ColorName.White))
        border.Width = Length.From(5, LengthUnit.Millimeter)

        border = cell.Format.DiagonalUpBorderLine

        border.Fill.SetSolid(Color.FromName(ColorName.White))
        border.Width = Length.From(5, LengthUnit.Millimeter)

        cell.Text.Format.VerticalAlignment = VerticalAlignment.Middle

        cell.Text.AddParagraph().AddRun("Cell 1-2")

        cell = row.Cells.AddNew()

        cell.Format.Fill.SetSolid(Color.FromName(ColorName.DarkBlue))

        cell.Text.Format.VerticalAlignment = VerticalAlignment.Bottom

        cell.Text.AddParagraph().AddRun("Cell 1-3")

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

Want more?

Next example GitHub

Check the next example or select an example from the menu. You can also download our examples from the GitHub.


Like it?

Download Buy

If you want to try the GemBox.Presentation yourself, you can download the free version. It delivers the same performance and set of features as the professional version, but with some operations limited. To remove the limitation, you need to purchase a license.