...
1. Include the SoftArtisans.OfficeWriter.PowerPoint
namespace in the code behind.
Csharpcode | ||
---|---|---|
1 | 1 | using SoftArtisans.OfficeWriter.PowerPointWriter; |
2. Instantiate the PowerPointTemplate
object.
Csharpcode | ||
---|---|---|
2 | 2 | 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.
Csharpcode | ||
---|---|---|
3 | 3 | PPTT.Open(Page.MapPath("templates\\Hello World.pptx")); |
4. Create a DataBindingProperties
object
Csharpcode | ||
---|---|---|
4 | 4 | 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.
Csharpcode | ||
---|---|---|
5 | 5 | 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.
Csharpcode | ||
---|---|---|
6 | 6 | PPTT.BindData(values, colnames, "DataSource1", DataProps); |
...
7. Call PowerPointTemplate.Process()
to insert the data into the file
Csharpcode | ||
---|---|---|
7 | 7 | PPTT.Process(); |
PowerPointTemplate.Process()
handles everything relating to inserting the data into the file.
8. Save the output
Csharpcode | ||
---|---|---|
8 | 8 | PPTT.Save(Page.Response, "Output.pptx", false); |
...
Congratulations, you have completed Hello World for PowerPointTemplate!
Final Code
Csharpcode | ||
---|---|---|
9 | 9 | 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); |
...