---
title: "Fill a PowerPoint template in C#"
url: https://recursiveai.org/onedocument/cookbook/fill-powerpoint-template/
description: "Replace text placeholders in a PowerPoint presentation with JSON data."
version: "1.0.0"
---

Replace text placeholders in a PowerPoint presentation with JSON data.

```shell
dotnet add package \
  RecursiveAI.OneDocument.Presentations
```

Requires [.NET 10](https://dotnet.microsoft.com/download/dotnet/10.0) (net10.0); .NET 9 and earlier aren’t supported.

The title placeholder in `template.pptx` contains `Hello {{ customer }}!`.

```csharp
using RecursiveAI.OneDocument.Presentations;
using RecursiveAI.OneDocument.Presentations
    .Templating;
using System.Text.Json;

using var deck = Presentation.Open(
    "template.pptx");
using var data = JsonDocument.Parse(
    """{"customer":"Ada"}""");
PresentationTemplate.Render(deck, data);
deck.SaveAs("filled.pptx");
```

Writes `filled.pptx` with the title “Hello Ada!”; the snippet prints nothing.

Unzip [the example](https://recursiveai.org/onedocument/cookbook/fill-powerpoint-template/fill-powerpoint-template.zip), then `dotnet run`.

## Full program

`template.pptx` has one slide with the title text:

```text
Hello {{ customer }}!
```

```csharp
using RecursiveAI.OneDocument.Presentations;
using RecursiveAI.OneDocument.Presentations
    .Templating;
using System.Text.Json;

using var deck = Presentation.Open(
    "template.pptx");
using var data = JsonDocument.Parse(
    """{"customer":"Ada"}""");
PresentationTemplate.Render(deck, data);
deck.SaveAs("filled.pptx");
Console.WriteLine(deck.Slides[0].Text.Trim());
```

`dotnet run` prints:

```text
Hello Ada!
```

Missing data produces a warning by default; strict template mode throws `TemplateException`.

## Related recipes

- [Create an Excel file](https://recursiveai.org/onedocument/cookbook/create-excel-file/)
- [Read an Excel file](https://recursiveai.org/onedocument/cookbook/read-excel-file/)
- [Fill a Word template](https://recursiveai.org/onedocument/cookbook/fill-word-template/)

## The short answer

Load the PPTX with `Presentation.Open`, then call `PresentationTemplate.Render` with your data and save the presentation. The binder edits the supplied presentation in place. In this example a title placeholder containing `Hello {{ customer }}!` becomes `Hello Ada!` in `filled.pptx`.

This is text templating, not arbitrary replacement of every object in a slide. Charts are not bound by the presentation template engine, and text growth does not resize shape boxes. Those boundaries matter when you design a recurring report: an unchanged chart and an overflowing title are not fixed by supplying more JSON fields.

## How do I fill a PowerPoint template in C#?

Start with a PPTX whose text has tags, rather than treating every existing word as a field name. Give each tag the corresponding data property. The sample has one title placeholder and one string property, `customer`. Rendering changes the title text, while saving writes the result to another file.

The binder reads paragraphs of slide text shapes, table cells and notes. It joins runs within a paragraph to recognize a tag even when formatting has split the tag across runs. A tag cannot span paragraphs or table cells. The inserted text uses the formatting at the start of the tag; following text keeps its own formatting. If the replacement looks wrong, inspect the template’s formatting at the opening delimiter rather than only at its last character.

Slide layouts and masters are not templated. Put a tag in the actual slide content that the binder reads. Keeping a tag only on a master is not a way to give every slide a separately populated value. The [presentation templating documentation](https://recursiveai.org/onedocument/docs/templating-pptx/) describes the units and scopes the binder handles.

Loops can repeat more than text, but scope is a deliberate design choice. A block can cover paragraphs, table rows, shapes or slides according to the template’s structure and scope. Build a small template and inspect one repeated item before expanding a whole deck. Copies get their own shape identifiers where required; the binder is not simply pasting the same XML identifiers into every position.

## How can I automatically populate my PowerPoint presentation with data from Excel?

Separate reading the spreadsheet from rendering the slides. Read the cells or typed rows you need, then supply a data object to the presentation binder. The rendering API consumes data; it does not automatically connect an Excel workbook to every visible object in a presentation. The [typed Excel reader](https://recursiveai.org/onedocument/cookbook/read-excel-rows-as-objects/) shows the spreadsheet half with a generated row model.

Decide which Excel values are already final. Spreadsheet formula readers can return cached results, so opening a source file does not by itself guarantee newly calculated values. Convert those results into the data fields your slide tags expect. For a simple customer title, this may be one string. A repeating report needs a collection whose members match the fields used inside the loop.

Do not assume this process updates embedded chart data. Chart replacement is an explicit gap in the presentation binder. Use text or table content only where those are genuinely the report you need, rather than claiming a chart was refreshed because a neighboring title changed.

Finally, allow enough space for real customer names. The binder keeps body properties and shape sizes; it does not refit text. The sample’s short greeting is not evidence that a paragraph of arbitrary length will fit the same placeholder. Review the populated deck’s layout in its intended viewer before distributing it.
