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

Load and Save PPTX in C# and VB.NET

With GemBox.Presentation, you can easily create a new presentation from an existing template presentation in your C# or VB.NET application.

The procedure is simple:

  • Load a template presentation.
  • Fill it with your data.
  • Save it as a new presentation.

The following example demonstrates how to generate a financial report from a template presentation by inserting data into the presentation content.

Screenshot
Template Use Screenshot

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

Upload your file(Drag files here)

Download a sample file

using System;
using System.IO;
using System.Linq;
using System.Text;
using GemBox.Presentation;
using GemBox.Presentation.Tables;

class Sample
{
    [STAThread]
    static void Main(string[] args)
    {
        // If using Professional version, put your serial key below.
        ComponentInfo.SetLicense("FREE-LIMITED-KEY");

        PresentationDocument presentation = PresentationDocument.Load("Template.pptx");

        // Retrieve first slide.
        Slide slide = presentation.Slides[0];

        // Retrieve "Title" placeholder and set shape text.
        Shape shape = slide.Content.Drawings.OfType<Shape>().Where(item => item.Placeholder?.PlaceholderType == PlaceholderType.CenteredTitle).First();
        shape.Text.Paragraphs[0].AddRun("ACME Corp - 4th Quarter Financial Results");

        // Retrieve second slide.
        slide = presentation.Slides[1];

        // Retrieve "Title" placeholder and set shape text.
        shape = slide.Content.Drawings.OfType<Shape>().Where(item => item.Placeholder?.PlaceholderType == PlaceholderType.Title).First();
        shape.Text.Paragraphs[0].AddRun("4th Quarter Summary");

        // Retrieve "Content" placeholder.
        shape = slide.Content.Drawings.OfType<Shape>().Where(item => item.Placeholder?.PlaceholderType == PlaceholderType.Content).First();

        // Set list text.
        shape.Text.Paragraphs[0].Elements.Clear();
        shape.Text.Paragraphs[0].AddRun("3 new products/services in Research and Development.");

        shape.Text.Paragraphs[1].Elements.Clear();
        shape.Text.Paragraphs[1].AddRun("Rollout planned for new division.");

        shape.Text.Paragraphs[2].Elements.Clear();
        shape.Text.Paragraphs[2].AddRun("Campaigns targeting new markets.");

        // Retrieve third slide.
        slide = presentation.Slides[2];

        // Retrieve "Title" placeholder and set shape text.
        shape = slide.Content.Drawings.OfType<Shape>().Where(item => item.Placeholder?.PlaceholderType == PlaceholderType.Title).First();
        shape.Text.Paragraphs[0].AddRun("4th Quarter Financial Highlights");

        // Retrieve a table.
        Table table = slide.Content.Drawings.OfType<GraphicFrame>().Where(item => item.Table != null).Select(item => item.Table).First();

        // Fill table data.
        table.Rows[1].Cells[1].Text.Paragraphs[0].Elements.OfType<TextRun>().First().Text = "$14.2M";
        table.Rows[1].Cells[2].Text.Paragraphs[0].Elements.OfType<TextRun>().First().Text = "(0.5%)";

        table.Rows[2].Cells[1].Text.Paragraphs[0].Elements.OfType<TextRun>().First().Text = "$1.6M";
        table.Rows[2].Cells[2].Text.Paragraphs[0].Elements.OfType<TextRun>().First().Text = "0.7%";

        table.Rows[3].Cells[1].Text.Paragraphs[0].Elements.OfType<TextRun>().First().Text = "$12.5M";
        table.Rows[3].Cells[2].Text.Paragraphs[0].Elements.OfType<TextRun>().First().Text = "0.3%";

        table.Rows[4].Cells[1].Text.Paragraphs[0].Elements.OfType<TextRun>().First().Text = "$2.3M";
        table.Rows[4].Cells[2].Text.Paragraphs[0].Elements.OfType<TextRun>().First().Text = "(0.2%)";

        presentation.Save("Template Use.pptx");
    }
}
Imports System.IO
Imports System.Text
Imports GemBox.Presentation
Imports GemBox.Presentation.Tables

Module Samples

    Sub Main()

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

        Dim presentation As PresentationDocument = PresentationDocument.Load("Template.pptx")

        ' Retrieve first slide.
        Dim slide As Slide = presentation.Slides(0)

        ' Retrieve "Title" placeholder And set shape text.
        Dim shape As Shape = slide.Content.Drawings.OfType(Of Shape).Where(Function(item) item.Placeholder?.PlaceholderType = PlaceholderType.CenteredTitle).First()
        shape.Text.Paragraphs(0).AddRun("ACME Corp - 4th Quarter Financial Results")

        ' Retrieve second slide.
        slide = presentation.Slides(1)

        ' Retrieve "Title" placeholder And set shape text.
        shape = slide.Content.Drawings.OfType(Of Shape).Where(Function(item) item.Placeholder?.PlaceholderType = PlaceholderType.Title).First()
        shape.Text.Paragraphs(0).AddRun("4th Quarter Summary")

        ' Retrieve "Content" placeholder.
        shape = slide.Content.Drawings.OfType(Of Shape).Where(Function(item) item.Placeholder?.PlaceholderType = PlaceholderType.Content).First()

        ' Set list text.
        shape.Text.Paragraphs(0).Elements.Clear()
        shape.Text.Paragraphs(0).AddRun("3 new products/services in Research and Development.")

        shape.Text.Paragraphs(1).Elements.Clear()
        shape.Text.Paragraphs(1).AddRun("Rollout planned for new division.")

        shape.Text.Paragraphs(2).Elements.Clear()
        shape.Text.Paragraphs(2).AddRun("Campaigns targeting new markets.")

        ' Retrieve third slide.
        slide = presentation.Slides(2)

        ' Retrieve "Title" placeholder And set shape text.
        shape = slide.Content.Drawings.OfType(Of Shape).Where(Function(item) item.Placeholder?.PlaceholderType = PlaceholderType.Title).First()
        shape.Text.Paragraphs(0).AddRun("4th Quarter Financial Highlights")

        ' Retrieve a table.
        Dim table As Table = slide.Content.Drawings.OfType(Of GraphicFrame).Where(Function(item) item.Table IsNot Nothing).Select(Function(item) item.Table).First()

        ' Fill table data.
        table.Rows(1).Cells(1).Text.Paragraphs(0).Elements.OfType(Of TextRun).First().Text = "$14.2M"
        table.Rows(1).Cells(2).Text.Paragraphs(0).Elements.OfType(Of TextRun).First().Text = "(0.5%)"

        table.Rows(2).Cells(1).Text.Paragraphs(0).Elements.OfType(Of TextRun).First().Text = "$1.6M"
        table.Rows(2).Cells(2).Text.Paragraphs(0).Elements.OfType(Of TextRun).First().Text = "0.7%"

        table.Rows(3).Cells(1).Text.Paragraphs(0).Elements.OfType(Of TextRun).First().Text = "$12.5M"
        table.Rows(3).Cells(2).Text.Paragraphs(0).Elements.OfType(Of TextRun).First().Text = "0.3%"

        table.Rows(4).Cells(1).Text.Paragraphs(0).Elements.OfType(Of TextRun).First().Text = "$2.3M"
        table.Rows(4).Cells(2).Text.Paragraphs(0).Elements.OfType(Of TextRun).First().Text = "(0.2%)"

        presentation.Save("Template Use.pptx")

    End Sub

End Module

Check next sample.