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

Table of Contents

Table of Contents
maxLevel1

Setting up the Template

About templates and data markers

A PowerPointWriter template is a PowerPoint presentation that contains PowerPointWriter data markers. A data marker is a line of text beginning with %%= that specifies a database column, variable, or array to insert into the presentation. PowerPointWriter supports data markers embedded in text. Data markers are added to a presentation in PowerPoint and then bound to data sources in code. PowerPointWriter populates the data markers with values from the data sources when the code is executed.

Excerpt

Part 1 of this tutorial demonstrates how to use data markers to import single rows of data.

Data marker syntax

The basic syntax for a data marker is %%=[DataSourceName].[ColumnName], where DataSourceName is the name of the data source and ColumnName is the name of the column in the data source. You need to follow these rules when naming data markers:

...

For more specific information about creating data markers, see How to use Data Markers

Adding data markers to the the template

The template for Part 1 consists of 6 2 slides populated with text and data markers.

Info
titleFollowing the Sample Code

In the downloadable PowerPointWriter_BasicTutorials.zip under ProjectProposal, there is a completed template file located in ProjectProposal/templates/part1_template.pptx.

1. Start Open Microsoft PowerPoint and start with a blank .pptx file. Save Sace the file as part1_template.pptx.

2. (optional) Set the presentation theme by going to the Design tab and selecting on the the built-in themes.

3. Add 3 text boxes to the first slide and populate the one you want to use as the title with the data marker %%=Proposal.Name

Image Removed

In the other two text boxes, add the %%=Proposal.Date, %%=Proposal.ReviewStatus data markers. The final slide A title slide should have been added to the presentation by default. If not, insert a title slide now.
This slide will hold our data markers for the employee name, company logo.

4. In the title text box add the text 'New Employee Training'.

5. Create a new text box underneath the title. This will hold our data marker for our employee name.

6. Place the text 'Welcome,' and the data marker %%=Employee.Name in this text box.
The data marker indicates where the data in the 'Employee' column from the 'Company' data source will be placed.

Our slide so far should look something like the one below.:

Image Removed

4. Add a new slide to the presentation. This slide should Image Added

Using the image modifier

Next we are going to add a data marker that holds the company logo to our slide. To place an image using a data marker into your presentation, the data marker must include the image modifier.

7. Add a text box to the upper left hand corner of the presentation. This will hold our company logo data marker.

8. Place the data marker %%=Company.Logo(image(4.25,1,2)) in the text box.

We are using the image modifier with 3 parameters. The first and second parameters are the width and height of the image respectively. All dimensions are in inches.

The third parameter is the scaling mode, which tells PowerPointWriter how to scale the image. In this example we are using scaling mode 2, meaning that the image will be enlarged or shrunk to fit within the bounds specified, but it will keep its natural aspect ratio.

For more information on scaling modes and the image modifier see the Quick Guide Importing Images.

Our first slide is now complete. It should look similar to the one below.

Image Added

Our next slide will contain an agenda for the rest of the training presentation.

9. Create a new content slide. The default content slide will consist of two text boxes, : one for the title and a large one for the body of the text. In

10. Give this slide the title 'Agenda'.

11. Add a third text box , place the in the bottom right of the slide to hold our company logo.

12. Place the data marker %%=Proposal.Name. Note that this is the same as the data marker used on our first slide.

The rest of the slide will contain additional data about the proposal from the 'Proposal' data source. The data markers we are adding are: %%=Proposal.Leader, %%=Proposal.Start, %%=Proposal.Estimate, %%= Proposal.Summary and %%=Proposal.ReviewStatus. Because PowerPointWriter supports data markers embedded in text, we only need one text box for this information.

The finished slide should look like the one below.

Image RemovedCompany.Logo(image(2)) in this text box.
This time, our image modifier is only taking one parameter, the scaling mode. This means that the image will take on the dimensions of the text box containing the data marker and be scaled according to the chose mode. Therefore, the text box should be the desired size for the imported image.

Importing Multiple Rows of Data

The body of our slide is going to contain a list of contents for the remainder of the presentation. It will include a list of training items imported for the specific role that the employee is training for.

13. In the large text box, create a new list. This can be done from the Home tab under Paragraph.

14. Add three items to this list:

  • 'Company History'
  • 'Product Overview'
  • 'Your Team:' followed by the data marker %%=Employee.Team

Our slide so far should look like the following:

Image Added

Under the 'Your Team' bullet, we are going to import a list of training items based on the position that the new employee was hired for. This will require that we import multiple rows from our data source. To import multiple rows in PowerPointWriter, the data marker must be placed in a list entry or table row. see Importing Multiple Rows of Data for more information.

15. Create a new list under the 'Your Team' bullet.

16. Add the data marker %%=Team.TrainingItems as the first entry in the new list.
The entirety of the 'TrainingItems' column will be imported into this list.

This completes our second slide. The completed slide is shown below.

Image Added

Adding a PowerPointWriter Reference in Visual Studio

Info
titleFollowing the Sample Code

In the sample code, the reference to SoftArtisans.OfficeWriter.PowerPointWriter.dll has already been added to the ProjectProposal project.

...

  1. Open Visual Studio and create a .NET project.
    • The sample code uses a web application.
  2. Add a reference to SoftArtisans.OfficeWriter.PowerPointWriter.dll
    • SoftArtisans.OfficeWriter.PowerPointWriter.dll is located under Program Files > SoftArtisans > OfficeWriter > dotnet > bin

Writing the Code

Info
titleFollowing the Sample Code

There is a sample web application page Part1.aspx and code behind Part1.aspx.cs available in the ProjectProposal/templates/part1_template.pptx directory that shows the completed code.

...

  1. Include the SoftArtisans.OfficeWriter.PowerPointWriter namespace in the code behind
    Code Block
    
    using SoftArtisans.OfficeWriter.PowerPointWriter;
    

...

  1. In the method that will

...

  1. create the presentation, instantiate the PowerPointTemplate object.
    Code Block
    
    PowerPointTemplate pptt = new PowerPointTemplate();
    

...

  1. Open the template file for the presentation.
    Code Block
    
    pptt.Open(Page.MapPath("//templates//part1_template.pptx"));
    

...

  1. Create a DatabindingProperties object for binding data to the template.
    Code Block
    
    DataBindingProperties dataProps = pptt.CreateDataBindingProperties();
    

...

  1. Create the 'Company' data source. When importing data with arrays, the values and column names are placed in separate arrays. This first array will contain the column names.
    Code Block
    
    //The 

...

  1. column 

...

  1. names 

...

  1. are 

...

  1. the same as the data markers
     string[] 

...

  1. columnNamesArray = {

...

  1. "

...

  1. Logo"};
    
  2. Create a second array that contains the values for the data source. When importing an image, the image value must be placed in a byte array. This can be done by using the File.ReadAllBytes method. See Importing Images for more information.
    Code Block
    
    Byte[] logoArray = System.IO.File.ReadAllBytes((Page.MapPath("//data//logo.png")));
    //Place the image byte[] into an object[] for the BindData call
    object[] valuesArray = {logoArray};
    
  3. Bind the 'Company data to the template. Make sure the data source name is the same as the name used in the template.
    Code Block
    
    pptt.BindData(valuesArray, columnNamesArray, "Company", dataProps);
    
  4. Create the 'Employee' data source. This contains the Employee's name and team
    Code Block
    
    string[] employeeColNames = {"Name", "

...

  1. Team"

...

  1. };
    object[] employeeValues = {"Amy Alberts", "

...

  1. Development"};
    
  2. Bind the Employee data to the presentation
    Code Block
    
    pptt.BindData(employeeValues, employeeColNames, "

...

  1. Employee", 

...

  1. dataProps);
    

...

  1. Get the data

...

  1. for the Team data source
    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.

    To create the DataTable, we will call a helper method GetCSVData that parses the CSV files and returns a DataTable with the values.
    Code Block
    
    DataTable teamData = GetCSVData((Page.MapPath("//data//Team.csv")));
    
  2. Bind the Team data to the presentation
    Code Block
    
    pptt.BindData(teamData, "Team", dataProps);
    

...

  1. Call process to import the data into the template and save the file.
    Code Block
    
    pptt.Process();
    

...

  1. Stream

...

  1. the

...

  1. output

...

  1. in

...

  1. the

...

  1. response

...

  1. as

...

  1. an

...

  1. attachment
    Code Block
    
    pptt.Save(Page.Response, "Part1_Output.

...

  1. pptx", false);
    

Final Code

Code Block
PowerPointTemplate pptt = new PowerPointTemplate();
pptt.Open(Page.MapPath("//templates//part1_template.pptx"));
DataBindingProperties dataProps = pptt.CreateDataBindingProperties();
objectstring[] valuesArraycolumnNamesArray = { "Project Name", "Project Date", "Review", "Leader Name", "Start Date", "Cost Estimate", "Project Summary" }Logo"};
Byte[] logoArray = System.IO.File.ReadAllBytes((Page.MapPath("//data//logo.png")));
object[] valuesArray = {logoArray};
pptt.BindData(valuesArray, columnNamesArray, "Company", dataProps);
string[] columnNamesArrayemployeeColNames = {"Name", "DateTeam", "ReviewStatus};
                object[] employeeValues = {"Amy Alberts", "Leader", "Start"Development"};
pptt.BindData(employeeValues, employeeColNames, "EstimateEmployee", "Summary"}dataProps);
DataTable teamData = GetCSVData((Page.MapPath("//data//Team.csv")));
pptt.BindData(valuesArrayteamData, columnNamesArray, "ProposalTeam", dataProps);
pptt.Process();
pptt.Save(Page.Response, "Part1_Output.xlsxpptx", false);

Downloads

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

Next Steps

Continue on to Part 2 - Repeat Behavior and Delete Slide The Continue Modifier