Page tree

Versions Compared

Key

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

...

Introduction

ExcerptThe DataBindingProperties allows customization of how data is imported by PowerPointTemplate.

Jump to:
Center
Table of Contents
maxLevel5
minLevel2

 

Definition

...

Excerpt

The DataBindingProperties

...

 object controls how data is bound when

...

the BindData

...

 method is called. DataBindingProperties can control the max rows of data per slide, the max total rows of data imported, and the slide to which the data is bound.

...

The BindData

...

 method requires a DataBindingProperties object as a parameter. Use the following line of code to create a new DataBindingProperties object.

Code Block

DataBindingProperties dataProps = pptt.CreateDataBindingProperties();

MaxRowsPerSlide

MaxRowsPerSlide controls how many of rows of data should be imported onto each slide.

Code Block

//Setting MaxRowsPerSlide
dataProps.MaxRowsPerSlide = 5;
Using MaxRowsPerSlide to fit data on multiple slides

When this property is set, PowerPointWriter will stop importing data when the limit is reached. In order to import all the data in a data source to your presentation, MaxRowsPerSlide should be used with the _Continue_ modifier. The default value is -1 which indicates that all the data in the data source should be imported to a single slide. For more information see Importing Multiple Rows of Data and Fitting Data on to Multiple Slides.

...

MaxRowstoImport

MaxRowsToImport determines how many total rows of data to import into a presentation. PowerPointWriter will stop importing data from the data source when this limit is reached. The default value is -1 which indicates that data will continue to be imported until the end of the data source is reached.

Code Block

//Setting MaxRowsToImport
dataProps.MaxRowstoImport = 10;
Importing a single row of data with MaxRowsToImport

Setting MaxRowsToImport = 1 will import a single row of data from a data set with multiple rows. For more information see Importing a Single Row of Data.

Slide

 

Slide controls which slide in a presentation a given data source should be imported into. Slide can be set to the 0-based index of the slide you wish to import data to. The default value is -1 which indicates that the data is not scoped to a particular slide.

Code Block

dataProps.Slide = 2;


Using Slide with Slides.CopySlide

 

Slide allows for data markers across the presentation to have the same name but import from different data sources. When used with the PowerPointApplication method, Slides.CopySlide(PowerPointWriter.Slide, Int), it is easy to programmatically create and populate multiple slides with the same layout.

Example

The Template

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

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.
Image Removed

 

See the CopySlide sample for an example of using the Slide DataBindingProperty with Slides.CopySlide.