How to add dynamic data (text data) to a PPT template and save it?

Meera 21 Reputation points
2021-10-24T15:51:41.473+00:00

I have a PPT template in which I need to programmatically replace some text fields with data that comes from my database then convert the ppt to pdf and send it as attachment in an email. I am not sure of how to change the content of text fields in the PowerPoint Presentation.

Developer technologies | C#
0 comments No comments
{count} votes

Accepted answer
  1. Meera Ravindran 76 Reputation points
    2021-10-25T04:28:24.37+00:00
    static void Main(string[] args)
        {
            // just file
            string fileName = GetFilePath("Resource\\Template.pptx");
            //open ppt
            using (PresentationDocument document = PresentationDocument.Open(fileName, true))
            {
                //looping each slide
                foreach (SlidePart slidePart in document.PresentationPart.SlideParts)
                {
                    // search for placeholder
                    DocumentFormat.OpenXml.Drawing.Text text = 
                        slidePart.RootElement.Descendants<DocumentFormat.OpenXml.Drawing.Text>().FirstOrDefault(x => x.Text == "[[placeholder1]]");
    
                    // change value in placeholder
                    if (text != null)
                        text.Text = "Changed text";
                }
    
                document.Save();
            }
        }
    

    Add the package DocumentFormat: https://www.nuget.org/packages/DocumentFormat.OpenXml/2.14.0-beta0001

    Wrap the placeholders in double square brackets in your PPT …eg., [[Name]].

    0 comments No comments

1 additional answer

Sort by: Most helpful
  1. PHẠM TUẤN KIỆT 1 Reputation point
    2022-02-18T02:47:28.177+00:00

    Wishing you success! Use the export to PowerPoint option in the Office web apps
    Using the Word web app, Microsoft 365 subscribers can easily convert Word documents into PowerPoint presentations. The presentation is created based on all the summaries of the Word file and using AI, images, fonts and icons can be added.

    Here are the steps to follow to use this option.

    Step 1 : Launch a browser (preferably a Chromium-based browser).

    Launch the browser
    Launch the browser
    Step 2 : Go to Word.Office.com and sign in with your Microsoft 365 account details.

    Launch Microsoft Word on the web
    Launch Microsoft Word on the web
    Step 3 : Open the Word document that you intend to convert.

    Open the Word document to be converted
    Open the Word document to be converted
    Step 4 : On the opened Word document, click File.

    Click File on the Word document
    Click File on the Word document
    Step 5 : Click Export.

    Click Export
    Click Export
    Step 6 : Select the Export to PowerPoint presentation option .

    Select the option Export to PowerPoint presentation
    Select the option Export to PowerPoint presentation
    Step 7 : Select your preferred PowerPoint theme and click Export.

    Choose your favorite PowerPoint theme
    Choose your favorite PowerPoint theme
    Step 8 : When the presentation is being prepared, the AI ​​will show you windows with notifications about the preparation of slides and content summary. Finally, a window will open notifying you that your presentation is ready. Click Open presentation to review the results in PowerPoint on the web.

    AI-designed presentations on PowerPoint on the web
    AI-designed presentations on PowerPoint on the web
    Step 9 : As you can see, the AI ​​has done an amazing job turning the Word document into a bright, colorful, neatly designed and formatted PowerPoint presentation.

    Designer in PowerPoint offers design options for every slide
    Designer in PowerPoint offers design options for every slide
    Step 10 : You can always change the suggested content according to your needs. As can be seen in the image above, Designer in PowerPoint will give you design options along with every slide. If you don't like this option, you can choose another one. Just click on the Design option and it will be changed.

    Add a logo to a slide in PowerPoint on the web
    Add a logo to a slide in PowerPoint on the web
    Step 11 : You can add icons, images, videos, etc… just like in any PowerPoint presentation. The example added the “Snacks” and “Movie Clapboard” icons to sync with the slide’s Entertainment theme.

    And not just from the web, you can also add media content from your own PC, while in PowerPoint on the web.

    You can add icons, images, videos, etc…
    You can add icons, images, videos, etc…
    Step 12 : The created presentation is saved on the root folder of OneDrive on the computer.

    You can also choose to save your presentation online, download a copy on your PC, then use it offline like any other presentation. There are also options to download as PDF, ODP and as well as images.

    Although this method is quick and simple, it has the following limitations:

    Only English language is supported.
    Cannot be used on Internet Explorer or Safari browsers .
    Media content can only be added after conversion.

    0 comments No comments

Your answer

Answers can be marked as Accepted Answers by the question author, which helps users to know the answer solved the author's problem.