Page tree

Versions Compared

Key

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

...

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:

  • Names must begin with a letter (A-Z, a-z)
    • The following is a list of characters allowed in data marker names without brackets: ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz1234567890_
  • Names must exactly match the names in the data source.
    • If a column in a database is 'Street Address', the ColumnName must be [Street Address] to account for the space. Similarly, if a data source name is "DataSource1", the data marker name must be DataSource1 or [DataSource1].

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

_.{info} # Open Microsoft PowerPoint and start with a blank .pptx file. Save the file as

.

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

...


  1. # (optional)

...

  1. Set

...

  1. the

...

  1. presentation

...

  1. theme

...

  1. by

...

  1. going

...

  1. to

...

  1. the

...

  1. Design

...

  1. tab

...

  1. and

...

  1. selecting

...

  1. one

...

  1. of

...

  1. the

...

  1. built-in

...

  1. themes.

...


  1. # A title slide should have been added to the presentation by default. If not, then insert a title slide now.
    These will hold our data markers for the title, date and review status of the proposed product.

  2. Populate the title textbox with the data marker %%=Proposal.Name. When the template is processed, this data marker will get the value from the 'Name' column in the 'Proposal' data source.

    Image Added
    # In the subtitle box, add %%=Proposal.Date.
    # Insert a new textbox and place in near the bottom of the slide. This will hold the review status of the project. Type %%=Proposal.ReviewStatus into the box. Format with desired font size and formatting.
    The final slide should look something like the one below.
    !SlideOneFinal.png|border=1!

...


  1. #

...

  1. Insert

...

  1. a

...

  1. new

...

  1. content

...

  1. slide.

...

  1. This

...

  1. slide

...

  1. should

...

  1. consist

...

  1. of

...

  1. two

...

  1. text

...

  1. boxes:

...

  1. one

...

  1. for

...

  1. the

...

  1. title

...

  1. and

...

  1. a

...

  1. large

...

  1. one

...

  1. for

...

  1. the

...

  1. body

...

  1. of

...

  1. text.

...



  1. In the title text box, place the data marker %%=Proposal.Name.

...

  1. Note

...

  1. that

...

  1. this

...

  1. is

...

  1. the

...

  1. same

...

  1. as

...

  1. the

...

  1. data

...

  1. marker

...

  1. used

...

  1. on

...

  1. our

...

  1. first

...

  1. slide,

...

  1. and

...

  1. will

...

  1. be

...

  1. populated

...

  1. with

...

  1. the

...

  1. same

...

  1. data.

...


  1. # In the large text box add the following text to a list:
  • Leader: %%=Proposal.Leader

...

  • Start

...

  • Date:

...

  • %%=Proposal.Start

...

  • Estimated

...

  • time

...

  • to

...

  • completion:

...

  • %%=Proposal.Estimate

...

  • Description:

...

  • %%=

...

  • Proposal.Summary

...

These

...

will

...

contain

...

additional

...

data

...

about

...

our

...

project.

...

PowerPointWriter

...

supports

...

data

...

markers

...

embedded

...

in

...

text,

...

so

...

only

...

one

...

text

...

box

...

is

...

needed

...

for

...

all

...

of

...

our

...

data

...

markers.

...

The

...

finished

...

slide

...

should

...

look

...

like

...

the

...

one

...

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.

{info}

Create

...

a

...

.NET

...

project

...

and

...

add

...

a

...

reference

...

to

...

the

...

PowerPointWriter

...

library.

...

  1. Open

...

  1. Visual

...

  1. Studio

...

  1. and

...

  1. create

...

  1. a

...

  1. .NET

...

  1. project.

...

    • The

...

    • sample

...

    • code

...

    • uses

...

    • a

...

    • web

...

    • application.

...

  1. Add

...

  1. a

...

  1. reference

...

  1. to

...

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

{info} # Include the

  1. Include the SoftArtisans.OfficeWriter.PowerPointWriter

...

  1. namespace

...

  1. in

...

  1. the

...

  1. code

...

  1. behind

...

  1. Code Block
    
    using SoftArtisans.OfficeWriter.PowerPointWriter;
    

...

  1. In the method that will actually 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 an array to hold the values that will appear in the presentation.
    Code Block
    
    //The values to display
    //This presentation is for a project proposal for a surgery scheduling software
    object[] valuesArray = { "Surgery Schedule", "January 1, 2014", "Under Review", "Pamela Blythe", "January 1, 2015", "6 months", "Software to schedule surgeries that require multiple resources such as surgeons, assistants, nurses, pre-op and post-op space, surgery theater, long-term recovery rooms." };
    

...

  1. Create a second array that contains the column names. The column names values must match the data markers in the template.
    Code Block
    
    //The column names are the same as the data markers
    string[] columnNamesArray = { "Name", "Date", "ReviewStatus", "Leader", "Start", "Estimate", "Summary" };
    

...

  1. Bind the 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, "Proposal", dataProps);
    

...

  1. Call process to import the data into the template and save the file.
    Code Block
    
    pptt.Process();
    
    //Stream the output in the response as an attachment
    pptt.Save(Page.Response, "Part1_Output.xlsx", false);
    

...

Final Code

Code Block

PowerPointTemplate pptt = new PowerPointTemplate();
pptt.Open(Page.MapPath("//templates//part1_template.pptx"));
DataBindingProperties dataProps = pptt.CreateDataBindingProperties();
object[] valuesArray = { "Surgery Schedule", "January 1, 2014", "Under Review", "Pamela Blythe", "January 1, 2015", "6 months", "Software 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);
pptt.Process();
pptt.Save(Page.Response, "Part1_Output.xlsx", false)
{newcode}

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

* [PowerPointWriter_BasicTutorials.zip|Tutorials^PowerPointWriter_BasicTutorials.zip]

h1. Next Steps

[Continue on to Part 2 - Repeat Behavior and Delete Slide | Part 2 - Repeat Behavior]

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