Description

This sample creates a presentation showing the college admissions test scores for a group of students. This sample demonstrates how to use PowerPointWriter formulas and using the Continue modifier with RepeatSlide marker.

The Data

The data for this sample is a data table of randomly generated college admission test scores. The following code is used to generate the data table.

private DataTable GetScores()
{
DataTable dt = new DataTable();
dt.Columns.Add("StudentID", typeof(string));
dt.Columns.Add("Reading", typeof(int));
dt.Columns.Add("Writing", typeof(int));
dt.Columns.Add("Math", typeof(int));
dt.Columns.Add("Total", typeof(int));
Random rand = new Random();
int rScore, wScore, mScore;
for (int i = 0; i < 30; ++i)
{
rScore = rand.Next(400, 800);
wScore = rand.Next(400, 800);
mScore = rand.Next(400, 800);
dt.Rows.Add(
string.Format("S{0:000000}", rand.NextDouble() * 1000000),
rScore, wScore, mScore, rScore + wScore + mScore
);
}
DataTable dtSorted = dt.Clone();
foreach (DataRow row in dt.Select("", "StudentID asc"))
dtSorted.ImportRow(row);
return dtSorted;
}

 

The Template

The template presentation consists of three slides containing data markers and formulas.
The second slide in our presentation contains the Continue modifier and RepeatSlide marker. When used together on a slide, PowerPointWriter will import data on to a slide until MaxRowsPerSlide is reached. Then, PowerPointWriter will copy the slide and continue adding data to the new slide. This will be repeated until all the data in the data source has been imported. See Fitting Data on to Multiple Slides to learn more.
The third slide contains several formulas summarizing the information from the first two slides. Formulas should follow the syntax %%=FORMULA_NAME(DataSource.DataCol). See Adding Formulas to a Presentation for more information and a list of supported formulas.

Our finished template will look like the following:

The Code

public void Formulas()
{
using (PowerPointTemplate pptt = new PowerPointTemplate())
{
pptt.Open("template.pptx");
//Get a Data Table of scores using the helper method
DataTable ScoreData = GetScores();
//Create DataBindingProperties
DataBindingProperties dataBindProps = pptt.CreateDataBindingProperties();

//Only import 10 rows on a slide
dataBindProps.MaxRowsPerSlide = 10;
//Bind the data
pptt.BindData(ScoreData, "Scores", dataBindProps);
pptt.Process();
pptt.Save(Page.Response, "ScoreReport.pptx", false);
}
}
private DataTable GetScores()
{
DataTable dt = new DataTable();
dt.Columns.Add("StudentID", typeof(string));
dt.Columns.Add("Reading", typeof(int));
dt.Columns.Add("Writing", typeof(int));
dt.Columns.Add("Math", typeof(int));
dt.Columns.Add("Total", typeof(int));
Random rand = new Random();
int rScore, wScore, mScore;
for (int i = 0; i < 30; ++i)
{
rScore = rand.Next(400, 800);
wScore = rand.Next(400, 800);
mScore = rand.Next(400, 800);
dt.Rows.Add(
string.Format("S{0:000000}", rand.NextDouble() * 1000000),
rScore, wScore, mScore, rScore + wScore + mScore
);
}
DataTable dtSorted = dt.Clone();
foreach (DataRow row in dt.Select("", "StudentID asc"))
dtSorted.ImportRow(row);
return dtSorted;
}

 

Result

The resulting formula slide is below:

Downloads

* Template:template.pptx
* Sample output: output.pptx