...
Hello World with PowerPointTemplate
Excerpt |
---|
PowerPointWriter's PowerPointTemplate approach allows you to write data to a template presentation that |
...
contains data markers. The dta markers tell PowerPointWriter where to bind specific sets of data. This tutorial will show you the basics of dynamically inserting data into a presentation using PowerPointTemplate by taking custom text from a web form textbox and inserting it into a template file. |
Setting up the template file
...
Info |
---|
The Hello World Tutorial can be found in the downloadable PowerPointWriter_HelloWorldC#. zip\. In the Hello World sample web application, the completed template file is located in \templates\Hello World.pptx. |
2. We are going to bind a single string value to a slide in a template file. To do this, we will first need to add a data marker to the slide where we want the value to appear.
...
Below is a screenshot of the completed template file from the Hello World sample:
3. Now the template file is done. Next is writing the code to bind the string value to the data marker.
...
1. Include the SoftArtisans.OfficeWriter.PowerPoint
namespace in the code behind.
Code Block |
---|
using SoftArtisans.OfficeWriter.PowerPointWriter;
|
2. Instantiate the PowerPointTemplate
object.
Code Block |
---|
PowerPointTemplate PPTT = new PowerPointTemplate();
|
3. Open the template file with PowerPointTemplate.Open
.
The PowerPointTemplate
object corresponds to a single template file, so a given PowerPointTemplate
instance can only have one template file open.
Code Block |
---|
PPTT.Open(Page.MapPath("templates\\Hello World.pptx"));
|
4. Create a DataBindingProperties
object
Code Block |
---|
DataBindingProperties DataProps = PPTT.CreateDataBindingProperties();
|
...
5. Get the data and create 2 arrays to hold the values and column names of the data you are importing.The column names should match the name of your data marker.
Code Block |
---|
string value = DataValueBox.Text.Trim();
string[] values = { value };
string[] colNames = { "DataValue" };
|
6. Call PowerPointTemplate.BindData()
to bind the data to the data marker. The data source name should match the value in your data marker.
Code Block |
---|
PPTT.BindData(values, colnames, "DataSource1", DataProps);
|
...
7. Call PowerPointTemplate.Process()
to insert the data into the file
Code Block |
---|
PPTT.Process();
|
PowerPointTemplate.Process()
handles everything relating to inserting the data into the file.
8. Save the output
Code Block |
---|
PPTT.Save(Page.Response, "Output.pptx", false);
|
...
9. Go to the web form page, PowerPointTemplate_HelloWorld.aspx, to try out the sample. In the output file, you will see that the data marker has been replaced with the custom text entered in the form.
Congratulations, you have completed Hello World for PowerPointTemplate!
Final Code
Code Block |
---|
using SoftArtisans.OfficeWriter.PowerPointWriter;
...
PowerPointTemplate PPTT = new PowerPointTemplate();
PPTT.Open(Page.MapPath("Hello World.pptx"));
DataBindingProperties DataProps = PPTT.CreateDataBindingProperties();
string value = DataValueBox.Text.Trim();
string[] values = { value };
string[] colNames = { "DataValue" };
PPTT.BindData(values, colNames, "DataSource1", DataProps);
PPTT.Process();
PPTT.Save(Page.Response, "Output.pptx", false);
|
...