Page tree

Versions Compared

Key

  • This line was added.
  • This line was removed.
  • Formatting was changed.

...

Example

The Template

Our template presentation contains a single slide with 2 data markers.
Image Modified

The code

The code below uses PowerPointApplication to copy the slide in our template, then passes the presentation to PowerPointTemplate to bind the data.

Code Block
            PowerPointApplication ppta = new PowerPointApplication();
            Presentation pres = ppta.Open("template.pptx");

            //Create a copy of the slide and add it to the end of the presentation
            Slide slideToCopy = pres.Slides[0];
            pres.Slides.CopySlide(slideToCopy, (pres.Slides.Count));
            
            //pass the presentation to PowerPointTemplate
            PowerPointTemplate pptt = new PowerPointTemplate();
            pptt.Open(ppta, pres);

            //Set the column names - will be the same for both slides
            string[] titleCol = {"Title"};
            string[] detailsCol = {"Details"};
            //Create a Data Binding Property
            DataBindingProperties dataProps = pptt.CreateDataBindingProperties();

            //Get the data for the first slide - Team Members
            //Data for the TrainingItem data source
            object[] titleArray = {"Team Members"};
            DataTable dtTeam = GetCSVData("Team.csv");
            //Set Slide to be the first slide in our presentation
            dataProps.Slide = 0;
            //Bind the Data
            pptt.BindData(titleArray, titleCol, "Training", dataProps );
            pptt.BindData(dtTeam, "TrainingItems", dataProps);

            //Get the data for the second slide - Agile Development
            object[] titleArray2 = { "AgileDevelopment" };
            DataTable dtAgile = GetCSVData("Agile.csv");
            //Change our Data Binding Properties to scope to the second slide
            dataProps.Slide = 1;
            //Bind the Data - only the array of values changed
            pptt.BindData(titleArray2, titleCol, "Training", dataProps);
            pptt.BindData(dtAgile, "TrainingItems", dataProps);

            //Process the data
            pptt.Process();

            pptt.Save("output.pptx");

Result

The resulsting output is a presentation containing 2 slides with the same layout but different data.