This sample demonstrates how to use PowerPointWriter's CopySlide method and Slide Data Binding Property to copy slides and bind them with different data. This makes it easy to programmatically create multiple slides with the same layout in your presentation.

This sample stores some of the data in a CSV file, which is available for download under Downloads. The CSV parser used in the example code was developed by Andrew Rissing and can be downloaded from Code Project.

The Template

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

The Code

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

public void CopySlide(){
            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 = { "Agile Development / Scrum" };
            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


     /// Uses a 3rd party generic CSV parser
     #region Utility Methods
     //Uses CSV reader
    System.Data.DataTable GetCSVData(string csvFileName)
        DataTable dt;
        using (GenericParserAdapter parser = new GenericParserAdapter(csvFileName))
            parser.ColumnDelimiter = ',';
            parser.FirstRowHasHeader = true;
            dt = parser.GetDataTable();
        return dt;


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


data:Team.csv Agile.csv
output: output.pptx