Page tree

Versions Compared

Key

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

...

Note

This is Part 2 of a 2-part tutorial series for the Project PropsalProposal scenario. It is recommended that you complete Part 1 - Getting Started with Data Markers before starting this section.

...

Fitting Data on to Multiple Slides

If a data source contains too much data

Passing between Template and Application

Delete Slide

Writing the Code

Our next slide will contain a list of estimated costs for the project. Create a new slide and give it the title 'Expected Costs'and add %%=Proposal.ReviewStatus to the bottom of the slide. Then, add a table with 2 rows and 3 columns.

This table will contain data from the 'Cost' data source. In the first row, label the table columns 'Type', 'Item', and 'Amount'. In the second row, add the data markers %%=Cost.Type, %%=Cost.Item, %%=Cost.Amt.

The 'Cost' data source contains more data than can fit on to a single slide. In order to ensure that data does not fall off of a slide, the Data Binding Property MaxRowsPerSlide can be set. When importing data, PowerPointWriter will stop importing onto a slide when it reaches the MaxRowsPerSlide limit.

However, we want to be sure that all the data from the 'Cost' data source is imported into our presentation. To do this the RepeatSlide marker can be used. When placed as the first item in the notes section of the slide, the RepeatSlide marker will copy that slide in place and continue importing data on to the new slide. This behavior will continue until the end of the data source or the MaxRowsToImport limit is reached. For more information see Fitting Data on to Multiple Slides.

To use the RepeatSlide marker, add the text '%%RepeatSlide' as the first string of text in the notes section of the 'Expected Costs' slide. Make sure there is a space between %%RepeatSlide and the next item of text. The completed slide should look like this:

!Slide4Final.png

Passing between Template and Application

Our template file contains an extra slide is not necessary for the presentation. PowerPointApplication has the ability to delete slides from a presentation. As we have been working in PowerPointTemplate we must pass the Template object to the Application object. This will be done in the code section of this tutorial. See [Passing between Template and Application for more information.

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

!Slide5Final.png

Writing the Code

We will reuse the code from Part 1 of this tutorial. We will take out the Process and Save calls and add our new code for Part 2.

Code Block

//Code from part 1
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);

1. Get the data for the Team and Cost data sets.

Info
titleFollowing the Sample

In the sample project, we are parsing CSV files with query results, rather than querying a live database. The CSV files are available under the data directory. There is a copy of the CSV parser, GenericParsing.dll in the bin directory of the project GetCSVData is defined in Part1.aspx.cs in a region marked Utility Methods.

These calls are to a helper method GetCSVData that parses the CSV files and returns a DataTable with the values.

Code Block

DataTable dtTeam = GetCSVData(Page.MapPath("//data//Part1_Team.csv"));
DataTable dtCost = GetCSVData(Page.MapPath("//data//Part1_Cost.csv"));

If you are following in your own project and would like to parse the CSV files as well, you will need to:

  • Add a reference to GenericParsing.dll
  • Include GeneringParsing at the top of your code.
  • Add the GetCSVData method that can be found in the sample code.

2. Set the MaxRowsPerSlide property to be 10.

Code Block

dataProps.MaxRowsPerSlie = 10;

3. Bind the Team and Cost data sets to the template

Code Block

pptt.BindData(dtTeam, "Team", dataProps);
pptt.BindData(dtCost, "Cost", dataProps);

4. Process the data

Code Block

pptt.Process();

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

Code Block

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

7. 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;

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

Code Block

int numSlides = pres.Slides.Count;

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

Code Block

ppta.Save(pres, Page.Response, "Part2_Output.pptx", false);

Final Code

Note

For information on writing this code, see Part 1 - Getting Started.

Code Block

//Code from Part 1
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);
//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();
PowerPointApplication ppta = new PowerPointApplication();
Presentation pres = ppta.Open(pptt);
int numSlides = pres.Slides.Count;
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.

...