Table of Contents |
---|
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.
Part 1 of this tutorial demonstrates how to use data markers to import single rows of data. |
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:
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
The template for Part 1 consists of 2 slides populated with text and data markers.
In the downloadable PowerPointWriter_BasicTutorials.zip under ProjectProposal, there is a completed template file located in ProjectProposal/templates/part1_template.pptx. |
%%=Proposal.Name
. When the template is processed, this data marker will get the value from the 'Name' column in the 'Proposal' data source.
%%=Proposal.Date
.
%%=Proposal.ReviewStatus
into the box. Format with desired font size and formatting.
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.
In the sample code, the reference to SoftArtisans.OfficeWriter.PowerPointWriter.dll has already been added to the ProjectProposal project. |
Create a .NET project and add a reference to the PowerPointWriter library.
There is a sample web application page |
using SoftArtisans.OfficeWriter.PowerPointWriter; |
PowerPointTemplate
object.
PowerPointTemplate pptt = new PowerPointTemplate(); |
pptt.Open(Page.MapPath("//templates//part1_template.pptx")); |
DataBindingProperties dataProps = pptt.CreateDataBindingProperties(); |
//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." }; |
//The column names are the same as the data markers string[] columnNamesArray = { "Name", "Date", "ReviewStatus", "Leader", "Start", "Estimate", "Summary" }; |
pptt.BindData(valuesArray, columnNamesArray, "Proposal", dataProps); |
pptt.Process(); //Stream the output in the response as an attachment pptt.Save(Page.Response, "Part1_Output.xlsx", false); |
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) |
You can download the code for the Basic PowerPointWriter Tutorials as a Visual Studio solution, which includes the Project Proposal.
Continue on to Part 2 - Repeat Behavior and Delete Slide