Create PowerPoint tables in C# and VB.NET
Table
elements are used to present content in a rectangular grid, separating data into columns and rows.
Tables and other content, such as charts or SmartArt diagrams, are embedded in a special kind of drawing, called a GraphicFrame
, contained in the SlideObject.Content
.
In the GemBox.Presentation API, the table-related types are grouped in the GemBox.Presentation.Tables
namespace.
With the example below, you will learn to create and populate a simple table using the GemBox.Presentation API.

using GemBox.Presentation;
using GemBox.Presentation.Tables;
class Program
{
static void Main()
{
// If using the 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 the 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
See also
Next steps
Published: December 13, 2018 | Modified: December 19, 2022 | Author: Marko Kozlina