In my last two posts, I showed you how to create a spreadsheet based on data and how to read data from spreadsheet. Today, I am going to move away from SpreadsheetML to talk about PresentationML. Specifically, I am going to show you how to create a rich presentation report based on data from a database.
Imagine a scenario where I'm a developer working for a fictional company called Adventure Works. In my company, we use a database to store all data pertaining to our sales force. For example, we keep track of our entire sales team in terms of contact information, territories they own, their total sales, bonus, etc. I have been asked to build a report generation tool that is able to take this data and create a viewable presentation. The sales team would like to have this solution run on the server, so there is a strict requirement that we cannot use the PowerPoint client.
Before I get into the details of my solution I want to call out a couple of things:
Okay, we're ready to get started. If you just want to jump straight into the code, feel free to download this solution here.
The scenario I listed above talks about reading sales person data and creating a report in the form of a presentation. The first thing I need to do is create a presentation template that I can use for my solution. In this case, my presentation template will contain a slide template that has placeholder regions for the following information:
My slide template will look like the following:
For each sales person in Adventure Works, I will need to clone the slide template, shown above, and fill in the necessary information based on data from my database. Below is some code that does the following:
At this point I have just cloned my slide template and added my new slide, which at the moment is an exact copy of the slide template, to my presentation. My next step is to swap out the placeholder text in my new slide with the appropriate data. I created a method that finds all placeholder text locations and swaps out the placeholder text with another string given a slide part. Here is the code:
My slide template includes one placeholder picture that is intended to represent the image of a sales person. In order for me to swap out this photo, I am going to need to do the following:
The following code accomplishes the above tasks:
Swapping out the photo is pretty easy since images are simply referenced via ids. In my case, all I need to do is find the image reference and swap it out with the image reference of the new image I added to the slide. The following code accomplishes these tasks:
Before we can call this solution complete we need to make sure to delete the slide template. Since I already know the relationship id of my slide template I can delete the slide with the following code:
Putting everything together and running my code, I will end up with the following output: