Table of Contents |
---|
This is Part 3 of a 3-part tutorial series for the Employee Training scenario. It is recommended that you complete Part 1 - Importing Data and Part 2 - The Continue Modifier before starting this section. |
There is a downloadable PowerPointWriter_BasicTutorials.zip with completed templates and code. The completed example of the template is available under EmployeeTraining/templates/part3_template.pptx. The code for this part of the tutorial can be found in Part3.aspx.cs. |
This part focuses on passing a presentation between PowerPointTemplate and PowerPointApplication in order to take advantage of the full range of features available with PowerPointWriter.
We will continue adding to our template from Part 2. The next part of our presentation will contain information about the Team the new employee will be working on.
This is the 8th and final slide in our template. This slide will be used as a template slide for 4 different data sets. To achieve this we will use the Slides.Copy method and the Slide data binding property.
There is a downloadable PowerPointWriter_BasicTutorials.zip with completed templates and code. The completed example of the template is available under ProjectProposal/templates/part3_template.pptx. The code for this part of the tutorial can be found in Part3.aspx.cs. |
We will start with an unprocessed template file containing all of the slides from the 3 parts of this tutorial.
PowerPointApplication ppta = new PowerPointApplication(); |
Presentation pres = ppta.Open(Page.MapPath("//templates//part3_template.pptx")); |
Slide slideToCopy = pres.Slides[7]; |
pres.Slides.CopySlide(slideToCopy, (pres.Slides.Count)); pres.Slides.CopySlide(slideToCopy, (pres.Slides.Count)); pres.Slides.CopySlide(slideToCopy, (pres.Slides.Count)); |
PowerPointTemplate pptt = new PowerPointTemplate(); pptt.Open(ppta, pres); |
//Code from Part 1 PowerPointTemplate pptt = new PowerPointTemplate(); pptt.Open(Page.MapPath("//templates//part1_template.pptx")); DataBindingProperties dataProps = pptt.CreateDataBindingProperties(); string[] columnNamesArray = {"Logo"}; Byte[] logoArray = System.IO.File.ReadAllBytes((Page.MapPath("//data//logo.png"))); object[] valuesArray = {logoArray}; pptt.BindData(valuesArray, columnNamesArray, "Company", dataProps); string[] employeeColNames = {"Name", "Team"}; object[] employeeValues = {"Amy Alberts", "Development"}; pptt.BindData(employeeValues, employeeColNames, "Employee", dataProps); DataTable teamData = GetCSVData((Page.MapPath("//data//Team.csv"))); pptt.BindData(teamData, "Team", dataProps); //Code from Part 2 DataTable dtCompanyHistory = GetCSVData(Page.MapPath("//data//CompanyHistory.csv")); dataProps.MaxRowsPerSlide = 5; pptt.BindData(dtCompanyHistory, "CompanyHistory", dataProps); DataTable dtProducts = GetCSVData(Page.MapPath("//data//Products.csv")); DataBindingProperties dataProps2 = pptt.CreateDataBindingProperties(); dataProps2.MaxRowsPerSlide = 2; pptt.BindData(dtProducts, "Products", dataProps2); |
string[] titleCol = { "TrainingItem" }; |
//Data for the TrainingItem data source object[] titleArrayTeam = { "Team Members" }; //Get the Team members data DataTable dtTeamMembers = GetCSVData(Page.MapPath("//data//TeamMembers.csv")); |
dataProps.Slide = 7; |
pptt.BindData(titleArrayTeam, titleCol, "Department", dataProps); pptt.BindData(dtTeamMembers, "TrainingItems", dataProps); |
//The 9th slide will be 'Agile Development / Scrum' object[] titleArrayAgile = { "Agile Development / Scrum" }; DataTable dtAgile = GetCSVData(Page.MapPath("//data//Agile.csv")); dataProps.Slide = 8; pptt.BindData(titleArrayAgile, titleCol, "Department", dataProps); pptt.BindData(dtAgile, "TrainingItems", dataProps); //The 10th slide will be 'Resources and Utilities' object[] titleArrayResources = { "Resources and Utilities" }; DataTable dtResources = GetCSVData(Page.MapPath("//data//Resources.csv")); dataProps.Slide = 9; pptt.BindData(titleArrayResources, titleCol, "Department", dataProps); pptt.BindData(dtResources, "TrainingItems", dataProps); //The final slide will be 'Expectations' object[] titleArrayExpectations = { "Expectations" }; DataTable dtExpectations = GetCSVData(Page.MapPath("//data//Expectations.csv")); dataProps.Slide = 10; pptt.BindData(titleArrayExpectations, titleCol, "Department", dataProps); pptt.BindData(dtExpectations, "TrainingItems", dataProps); |
pptt.Process(); pptt.Save(Page.Response, "part3_OutPut.pptx", false); |
For information on writing this code, see Part 1 - Importing Data and Part 2 - The Continue Modifier. |
PowerPointApplication ppta = new PowerPointApplication(); Presentation pres = ppta.Open(Page.MapPath("//templates//part3_template.pptx")); Slide slideToCopy = pres.Slides[7]; pres.Slides.CopySlide(slideToCopy, (pres.Slides.Count)); pres.Slides.CopySlide(slideToCopy, (pres.Slides.Count)); pres.Slides.CopySlide(slideToCopy, (pres.Slides.Count)); PowerPointTemplate pptt = new PowerPointTemplate(); pptt.Open(ppta, pres); //Code from Part 1 DataBindingProperties dataProps = pptt.CreateDataBindingProperties(); string[] columnNamesArray = { "Logo" }; Byte[] logoArray = System.IO.File.ReadAllBytes((Page.MapPath("//data//logo.png"))); object[] valuesArray = { logoArray }; pptt.BindData(valuesArray, columnNamesArray, "Company", dataProps); string[] employeeColNames = { "Name", "Team" }; object[] employeeValues = { "Amy Alberts", "Development" }; pptt.BindData(employeeValues, employeeColNames, "Employee", dataProps); DataTable teamData = GetCSVData((Page.MapPath("//data//Team.csv"))); pptt.BindData(teamData, "Team", dataProps); //Code from Part 2 DataTable dtCompanyHistory = GetCSVData(Page.MapPath("//data//CompanyHistory.csv")); dataProps.MaxRowsPerSlide = 5; pptt.BindData(dtCompanyHistory, "CompanyHistory", dataProps); DataTable dtProducts = GetCSVData(Page.MapPath("//data//Products.csv")); DataBindingProperties dataProps2 = pptt.CreateDataBindingProperties(); dataProps2.MaxRowsPerSlide = 2; pptt.BindData(dtProducts, "Products", dataProps2); //add the data from part 3 string[] titleCol = { "TrainingItem" }; object[] titleArrayTeam = { "Team Members" }; DataTable dtTeamMembers = GetCSVData(Page.MapPath("//data//TeamMembers.csv")); dataProps.Slide = 7; pptt.BindData(titleArrayTeam, titleCol, "Department", dataProps); pptt.BindData(dtTeamMembers, "TrainingItems", dataProps); object[] titleArrayAgile = { "Agile Development / Scrum" }; DataTable dtAgile = GetCSVData(Page.MapPath("//data//Agile.csv")); dataProps.Slide = 8; pptt.BindData(titleArrayAgile, titleCol, "Department", dataProps); pptt.BindData(dtAgile, "TrainingItems", dataProps); object[] titleArrayResources = { "Resources and Utilities" }; DataTable dtResources = GetCSVData(Page.MapPath("//data//Resources.csv")); dataProps.Slide = 9; pptt.BindData(titleArrayResources, titleCol, "Department", dataProps); pptt.BindData(dtResources, "TrainingItems", dataProps); object[] titleArrayExpectations = { "Expectations" }; DataTable dtExpectations = GetCSVData(Page.MapPath("//data//Expectations.csv")); dataProps.Slide = 10; pptt.BindData(titleArrayExpectations, titleCol, "Department", dataProps); pptt.BindData(dtExpectations, "TrainingItems", dataProps); pptt.Process(); pptt.Save(Page.Response, "part3_OutPut.pptx", false); |
You can download the code for the Basic PowerPointWriter Tutorials as a Visual Studio solution, which includes the Project Proposal.
See our Quick Guides and Samples for more advanced topics.