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

An PowerPointWriter template is an 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

This tutorial demonstrates how to use data markers to import single and multiple rows of data, using the repeat slide marker, and removing slides.

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

Our template consists of 5 slides populated with text and data markers.

...

In this section, we are only importing single rows of data. Importing multiple rows will be handled in part 2. The finished slide should look like the one below.

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/ directory that shows the completed code.

...

//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 = { "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);
pptt.Process();
pptt.Save(Page.Response, "Part1_Output.xlsx", 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