...
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, it is easy to programmatically create and populate multiple slides with the same layout.
Example |
---|
The TemplateOur template presentation contains a single slide with 2 data markers.
Wiki Markup |
---|
!template.pptx! |
The codeThe 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 |