Page tree

Versions Compared

Key

  • This line was added.
  • This line was removed.
  • Formatting was changed.
Comment: Migration of unmigrated content due to installation of a new plugin

...

Info
titleFollowing the Sample

There is a downloadable SomeFile 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.

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.

Adding to the Template

Passing between Template and Application

Add a new slide to the template from Part 2. This slide will be an optional extra slide that will not be included in the final presentation. Our template file contains an extra slide with a disclaimer that is not necessary for the presentationcould be removed if necessary, for instance if the presentation was a draft. In this example, we will show you how to remove an optional slide.

The extra slide in the template file look like the following:

Passing between Template and Application

In order to delete this slide we will be using PowerPointApplication's Delete method. However, we have so far been working only in PowerPointTemplate. In order to take advantage of the methods in PowerPointApplication, we must first pass the completed template file to PowerPointApplication. This will be done in the code Writing the Code section of this tutorial. See Passing between Template and Application for more information.

Writing the Code

Info
titleFollowing the Sample

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 reuse the code from Part 1 and Part 2 of this tutorial. We will take out the Save call and add our new code for Part 3.

Code Block
//Code from parts 1 and 2
PowerPointTemplate pptt = new PowerPointTemplate();
pptt.Open(Page.MapPath("//templates//part1_template.pptx"));
DataBindingProperties dataProps = pptt.CreateDataBindingProperties();
object[] valuesArray = { "Project Name", "Project Date", "Review", "Leader Name", "Start Date", "Cost Estimate", "Project Summary" };
string[] columnNamesArray = {"Name", "Date", "ReviewStatus", "Leader", "Start", "Estimate", "Summary"};
pptt.BindData(valuesArray, columnNamesArray, "Proposal", dataProps);

51. Pass the Template object to PowerPointApplication so that Application PowerPointApplication methods can be used.

Code Block
PowerPointApplication ppta = new PowerPointApplication();
Presentation pres = ppta.Open(pptt);

72. We want to delete the last slide in our presentation, so we need to know how many slides there are. We can use Slides.Count to get this information.

Code Block
int numSlides = pres.Slides.Count;

63. Use the Slides.Delete method to delete the last slide. It takes an integer representing the index of the slide to delete as a parameter.

Code Block
pres.Slides.Delete(numSlides - 1);

74. Save the final presentation and stream it in the response.

...

Code Block
//Code from Part 1
PowerPointTemplate pptt = new PowerPointTemplate();
pptt.Open(Page.MapPath("//templates//part1_template.pptx"));
DataBindingProperties dataProps = pptt.CreateDataBindingProperties();
object[] valuesArray = { "ProjectSurgery NameSchedule", "Project DateJanuary 1, 2014", "Under Review", "LeaderPamela NameBlythe", "Start DateJanuary 1, 2015", "Cost6 Estimatemonths", "Project SummarySoftware to schedule surgeries that require multiple resources such as surgeons, assistants, nurses, pre-op and post-op space, surgery theater, long-term recovery rooms." };
string[] columnNamesArray = { "Name", "Date", "ReviewStatus", "Leader", "Start", "Estimate", "Summary" };
pptt.BindData(valuesArray, columnNamesArray, "Proposal", dataProps);
//Code from Part 2
DataTable dtTeam = GetCSVData(Page.MapPath("//data//Team.csv"));
DataTable dtCost = GetCSVData(Page.MapPath("//data//Cost.csv"));
dataProps.MaxRowsPerSlide = 10;
pptt.BindData(dtTeam, "Team", dataProps);
pptt.BindData(dtCost, "Cost", dataProps);
pptt.Process();
//Code from Part 3
PowerPointApplication ppta = new PowerPointApplication();
Presentation pres = ppta.Open(pptt);
pres.Slides.Delete(numSlides - 1)
ppta.Save(pres, Page.Response, "Part2_Output.pptx", false);

Downloads

You can download the code for the Basic PowerPointWriter Tutorials as a Visual Studio solution, which includes the Project Proposal.