...
Info |
---|
In the sample code, the completed file is: PowerPointTemplate_HelloWorld.aspx.[cs/vb]. The corresponding web form is PowerPointTemplate_HelloWorld.aspx. |
...
Csharp | ||||
---|---|---|---|---|
| ||||
using SoftArtisans.OfficeWriter.PowerPointWriter; | ||||
Vbnet | 1 | 1 | ||
Imports SoftArtisans.OfficeWriter.PowerPointWriter |
2. Instantiate the PowerPointTemplate
object.
Csharp | ||||
---|---|---|---|---|
| ||||
PowerPointTemplate PPTT = new PowerPointTemplate(); | ||||
Vbnet | 2 | 2 | ||
Dim PPTT As 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.
Csharp | ||||
---|---|---|---|---|
| ||||
PPTT.Open(Page.MapPath("templates\\Hello World.pptx")); | ||||
Vbnet | 3 | 3 | ||
PPTT.Open(Page.MapPath("templates\Hello World.pptx")) |
4. Create a DataBindingProperties
object
Csharp | ||||
---|---|---|---|---|
| ||||
DataBindingProperties DataProps = PPTT.CreateDataBindingProperties(); | ||||
Vbnet | 4 | 4 | ||
Dim DataProps As DataBindingProperties = PPTT.CreateDataBindingProperties() |
The DataBindingProperties
object can be used to change the behavior of how data is imported. For example, if we were importing multiple rows of data, we can use the DataBindingProperties.MaxRowsPerSlide
property to limit the number of rows that are imported. In this sample, we won't be changing any of the import properties, but we still need the DataBindingProperties
object to bind data.
...
Csharp | ||||
---|---|---|---|---|
| ||||
string value = DataValueBox.Text.Trim(); string[] values = { value }; string[] colNames = { "DataValue" }; | ||||
Vbnet | 5 | 5 | ||
|
6. Call PowerPointTemplate.BindData()
to bind the data to the data marker. The data source name should match the value in your data marker.
Csharp | ||||
---|---|---|---|---|
| ||||
{vbnet:6} PPTT.BindData(values, colnames, "DataSource1", DataProps); | ||||
Vbnet | 6 | 6 | ||
PPTT.BindData(values, colnames, "DataSource1", DataProps) |
Note that we need to pass the DataBindingProperties
object, even though none of the DataBindingProperties
are active.
7. Call PowerPointTemplate.Process()
to insert the data into the file
Csharp | ||||
---|---|---|---|---|
| ||||
PPTT.Process(); | ||||
Vbnet | 7 | 7 | ||
PPTT.Process() |
PowerPointTemplate.Process()
handles everything relating to inserting the data into the file.
...
Csharp | ||||
---|---|---|---|---|
| ||||
PPTT.Save(Page.Response, "Output.pptx", false); | ||||
Vbnet | 8 | 8 | ||
PPTT.Save(Page.Response, "Output.pptx", False) |
There are several options for PowerPointTemplate.Save
including: save to disk, save to memory stream, stream back to the client inline, and stream back to the client as an attachment. In this case, we're streaming the presentation back to the client as an attachment.
Also, PowerPointWriter does not convert between file formats, so it is important that the file extension on the output file matches the file extension of the original template file.
...
Csharp | ||||
---|---|---|---|---|
| ||||
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); | ||||
Vbnet | 9 | 9 | ||
|
Downloads
You can download the code for the hello world tutorial as a Visual Studio solution.
- PowerPointWriter_BasicTutorialsHelloWorldC#.zip