Table of Contents |
---|
This is Part 2 of a 3-part tutorial series for the Employee Training scenario. It is recommended that you complete Part 1 - Importing Data before starting this section. |
There is a downloadable PowerPointWriter_BasicTutorials.zip with completed templates and code. The completed example of the template is available under EmployeeTraining/templates/part2_template.pptx. The code for this part of the tutorial can be found in Part2.aspx.cs. |
This part focuses on taking advantage of PowerPointWriter's Continue modifier.
We are going to start with the template file as it was at the end of Part 1.
We will reuse the code from Part 1 of this tutorial. We will take out the Process and Save calls and add our new code for Part 2.
//Code from part 1 PowerPointTemplate pptt = new PowerPointTemplate(); pptt.Open(Page.MapPath("//templates//part1_template.pptx")); DataBindingProperties dataProps = pptt.CreateDataBindingProperties(); string[] columnNamesArray = {"Logo"}; Byte[] logoArray = System.IO.File.ReadAllBytes((Page.MapPath("//data//logo.png"))); object[] valuesArray = {logoArray}; pptt.BindData(valuesArray, columnNamesArray, "Company", dataProps); string[] employeeColNames = {"Name", "Team"}; object[] employeeValues = {"Amy Alberts", "Development"}; pptt.BindData(employeeValues, employeeColNames, "Employee", dataProps); DataTable teamData = GetCSVData((Page.MapPath("//data//Team.csv"))); pptt.BindData(teamData, "Team", dataProps); |
1. Get the data for the CompanyHistory.
In the sample project, we are parsing CSV files with query results, rather than querying a live database. The CSV files are available under the data directory. There is a copy of the CSV parser, |
These calls are to a helper method GetCSVData
that parses the CSV files and returns a DataTable
with the values.
If you are following in your own project and would like to parse the CSV files as well, you will need to:
GenericParsing.dll
GeneringParsing
at the top of your code.GetCSVData
method that can be found in the sample code.DataTable dtCompanyHistory = GetCSVData(Page.MapPath("//data//COmpanyHistory.csv")); |
2. Set the MaxRowsPerSlide property. We will use the DataBindingProperties object created in Part 1 of this tutorial. Only 5 Company History items will be on a single slide.
dataProps.MaxRowsPerSlide = 5; |
3. Bind the CompanyHistory data to the presentation
pptt.BindData(dtCompanyHistory, "CompanyHistory", dataProps); |
4. Get the data for the Products data source
DataTable dtProducts = GetCSVData(Page.MapPath("//data//Products.csv")); |
5. Create a new DataBindingProperties object and set the MaxRowsPerSlide property to be 2
DataBindingProperties dataProps2 = pptt.CreateDataBindingProperties(); dataProps2.MaxRowsPerSlide = 2; |
6. Bind the Products data source to the presentation
pptt.BindData(dtProducts, "Products", dataProps2); |
7. Process the template to import the data
pptt.Process(); |
8.Save the final presentation and stream it in the response.
ppta.Save(pres, Page.Response, "Part2_Output.pptx", false); |
For information on writing this code, see Part 1 - Importing Data. |
//Code from Part 1 PowerPointTemplate pptt = new PowerPointTemplate(); pptt.Open(Page.MapPath("//templates//part1_template.pptx")); DataBindingProperties dataProps = pptt.CreateDataBindingProperties(); string[] columnNamesArray = {"Logo"}; Byte[] logoArray = System.IO.File.ReadAllBytes((Page.MapPath("//data//logo.png"))); object[] valuesArray = {logoArray}; pptt.BindData(valuesArray, columnNamesArray, "Company", dataProps); string[] employeeColNames = {"Name", "Team"}; object[] employeeValues = {"Amy Alberts", "Development"}; pptt.BindData(employeeValues, employeeColNames, "Employee", dataProps); DataTable teamData = GetCSVData((Page.MapPath("//data//Team.csv"))); pptt.BindData(teamData, "Team", dataProps); //Code from Part 2 DataTable dtCompanyHistory = GetCSVData(Page.MapPath("//data//CompanyHistory.csv")); dataProps.MaxRowsPerSlide = 5; pptt.BindData(dtCompanyHistory, "CompanyHistory", dataProps); DataTable dtProducts = GetCSVData(Page.MapPath("//data//Products.csv")); DataBindingProperties dataProps2 = pptt.CreateDataBindingProperties(); dataProps2.MaxRowsPerSlide = 2; pptt.BindData(dtProducts, "Products", dataProps2); pptt.Process(); pptt.Save(Page.Response, "Part2_Output.pptx", false); |
You can download the code for the Basic PowerPointWriter Tutorials as a Visual Studio solution, which includes the Project Proposal.
Continue on to Part 3 - Passing to PowerPointApplication