IntroIntro
Excerpt |
---|
This guide will explain how to import a single row of values into a PowerPoint presentation using data markers. This assumes a basic understanding of data markers. |
...
Center |
---|
Jump to: |
Table of Contents | ||||
---|---|---|---|---|
|
Setting up the Template
The template file should contain data markers following proper data marker syntax. Each copy of a given data marker will be populated with the same value. If the data marker appears in a table row or list entry, nothing will be automatically repeated if only one row is imported.
Binding Data
PowerPointTemplate has a single method for binding data to the data markers that are located in the template: PowerPointTemplate.BindData. Depending on the data source type and the number of rows in the data source, PowerPointWriter will either import a single row of data or import multiple rows by repeating sections of the presentation.
By default, every appearance of a data marker will be populated with the same data. For example, if %%=Header.CompanyLogo(image) appears on multiple slides, each data marker will be populated with the company logo. This behavior can be overwritten using data binding properties.
Importing a single row of data with BindData
There are two There are several ways to import a single row of data into a data markerpresentation: 1.
- Use a single dimensional array
...
- Use a multi-dimensional data source AND
- The data source only has one row of data
- DataBindingProperties.MaxRowsToImport is set to 1
Single Dimensional Arrays
Methods:
[PowerPointTemplate.BindData(Object[],String[],String,DataBindingProperties)]
[PowerPointTemplate.BindData(Object[][],String[],String,DataBindingProperties)]
[PowerPointTemplate.BindData(Object
,
,String[],String,DataBindingProperties)]
Arrays don't have built-in means to store column names. The user must specify the column names in a string array that is passed to {{PowerPointTemplate.BindData}} at run time.
If a multidimensional array (Object[,]
) or a jagged array (Object[][]
) contains multiple rows, PowerPointWriter will import all the rows using built-in repeating behavior. To import a single row of data using a multidimensional or jagged array, the array can only contain a single row of data. For more information about using arrays to import multiple rows of data, please see Importing Multiple Rows of Data.
Examples
One dimensional array:
Code Block | csharp | csharp |
---|---|---|
title | C# | |
Code Block | ||
| ||
PowerPointTemplate pptt = new PowerPointTemplate(); pptt.Open(@"C:\DataBinding\ArrayBindingTemplate.pptx"); string[] values = {"Hello World", "subtitle"}; string[] colNames = {"header", "subtitle"}; DataBindingProperties DataProps = pptt.CreateDataBindingProperties(); pptt.BindData(values, colNames, "DataSource1", DataProps); pptt.Process(); pptt.Save(Page.Response, "ArrayBinding.pptx", false); |
Code Block | ||||||
---|---|---|---|---|---|---|
|
||||||
Dim pptt As New PowerPointTemplate() ; pptt.Open("C:\DataBinding\ArrayBindingTemplate.pptx") Dim values = New String() {"Hello World", "subtitle"} Dim colNames = New String() {"header", "subtitle"} Dim DataProps As DataBindingProperites = pptt.CreateDataBindingProperties(); pptt.BindData(values, colNamescolnames, "DataSource1", DataProps); pptt.Process() pptt.Save(Page.ResponseRepponse, _ "ArrayBinding.pptx", _ False) |
...
Multi-dimensional data sources
If a multi-dimensional data source has only one row of data, the automatic repeating behavior will not occur. This is consistent for any of the multi-dimensional data sources supported by BindData:
- Jagged and multi-dimensional arrays
- Custom objects (IEnumerable<T>)
- System.IDataReader and System.DataTable
Setting MaxRowsToImport to 1
MaxRowsToImport is a data binding property on the DataBindingProperties object that can be used to control limit the number of rows that are imported, regardless of how many rows of data to import from are actually in the data set. When using data sources other than a single dimensional array, a single row of data can be imported by setting MaxRowsToImport to 1.source.
Code Block | ||||||
---|---|---|---|---|---|---|
|
| |||||
DataBindingProperties DataPropsdataProps = ppttppt.DataBindingPropertiesCreateDataBindingProperties(); DataPropsdataProps.MaxRowsToImport = 1; |
For more information about importing data from different data sources see Importing Multiple Rows of Data.
ppt.BindData(getDataTable(), "DataSourceName", dataProps); |