Syncfusion Feedback

Create and Format Tables Using Syncfusion .NET PowerPoint Library

The Syncfusion® .NET PowerPoint Library enables you to create, edit, and format tables in PowerPoint slides. Rows and cells can be iterated easily.

Create and format PowerPoint tables using C#

Learn how to create edit and format tables in PowerPoint presentations programmatically using C# with the Syncfusion .NET PowerPoint library. This guide demonstrates adding tables with customizable rows and columns and applying formatting to organize data effectively.

Step 1: Create a new project

Start by creating a new C# Console Application project.

Step 2: Install the NuGet package

Add the Syncfusion.Presentation.Net.Core package to your project from NuGet.org.

Step 3: Add required namespaces to create and format PowerPoint tables

Add the following namespaces to your Program.cs file:

using Syncfusion.Presentation;
using System;

Step 4: Create a PowerPoint presentation

Create a new presentation and add a blank slide.

Run

//Create a new instance of PowerPoint Presentation file
using IPresentation pptxDoc = Presentation.Create();
//Add slide to the Presentation
ISlide slide = pptxDoc.Slides.Add(SlideLayoutType.Blank);

Step 5: Add a table

Add a table with two rows and two columns to the slide.

//Add table to the slide
ITable table = slide.Shapes.AddTable(2, 2, 100, 120, 300, 200);

Step 6: Format table cells

Add content to each table cell and apply formatting like colors and margins.

//Retrieve each cell and fills text content to the cell
ICell cell = table[0, 0];
//Set the column width for a cell; this sets the width for entire column
cell.ColumnWidth = 400;
//Set the margin for the cell
cell.TextBody.MarginBottom = 0;
cell.TextBody.MarginLeft = 58;
cell.TextBody.MarginRight = 29;
cell.TextBody.MarginTop = 65;
//Set the back color for the cell
cell.Fill.SolidFill.Color = ColorObject.Orange;
cell.TextBody.AddParagraph("First Row and First Column");

cell = table[0, 1];
//Set the margin for the cell
cell.TextBody.MarginLeft = 58;
cell.TextBody.MarginRight = 29;
cell.TextBody.MarginTop = 65;
//Set the back color for the cell
cell.Fill.SolidFill.Color = ColorObject.BlueViolet;
cell.TextBody.AddParagraph("First Row and Second Column");

cell = table[1, 0];
//Set the margin for the cell
cell.TextBody.MarginLeft = 58;
cell.TextBody.MarginRight = 29;
cell.TextBody.MarginTop = 65;
//Set the back color for the cell
cell.Fill.SolidFill.Color = ColorObject.SandyBrown;
cell.TextBody.AddParagraph("Second Row and First Column");

cell = table[1, 1];
//Set the margin for the cell
cell.TextBody.MarginLeft = 58;
cell.TextBody.MarginRight = 29;
cell.TextBody.MarginTop = 65;
//Set the back color for the cell
cell.Fill.SolidFill.Color = ColorObject.Silver;
cell.TextBody.AddParagraph("Second Row and Second Column");

Step 7: Save the PowerPoint presentation

Save the presentation with the formatted table to a file stream.

FileStream outputStream = new(Path.GetFullPath(@"Output/Result.pptx"), FileMode.Create, FileAccess.ReadWrite);
pptxDoc.Save(outputStream);
//Close stream and presentation
outputStream.Close();
pptxDoc.Close();

Get started quickly by downloading the installer and checking license information on the Downloads page.

Syncfusion .NET PowerPoint Library Resources

Explore these resources for comprehensive guides, knowledge base articles, insightful blogs, and ebooks.