...
6. Place the text 'Welcome,' and the data marker %%=CompanyEmployee.Employee Name in this text box.
The data marker indicates where the data in the 'Employee' column from the 'Company' data source will be placed.
...
8. Place the data marker %%=Company.Logo(image(2,4.25,1,2)) in the text box.
We are using the image modifier with 3 parameters. The first and second parameters are the width and height of the image respectively. All dimensions are in inches.
The third parameter is the scaling mode, which tells PowerPointWriter to use how to scale the image. In this example we are using scaling mode 2, meaning that the image will be enlarged or shrunk to fit within the bounds specified, but it will keep its natural aspect ratio. The second and third parameters are the width and height of the image respectively. All dimensions are in inches.
For more information on scaling modes and the image modifier see the Quick Guide Importing Images.
...
Our next slide will contain an agenda for the rest of the training presentation, including a list of team members.
9. Create a new content slide. The default content slide will consist of two text boxes: one for the title and a large one for the body of the text.
...
The body of our slide is going to contain a list of contents for the remainder of the presentation. It will also include a list of team members training items imported for the new employee, which will be imported using a data markerspecific role that the employee is training for.
13. In the large text box, create a new list. This can be done from the Home tab under Paragraph.
14. Add three items to this list:
- 'Company History'
- 'Product Overview'
- 'Your Team:' followed by the data marker %%=Employee.Team
...
Our slide so far should look like the following:
...
Under the 'Your Team' bullet, we are going to import a list of team members for the training items based on the position that the new employee was hired for. This will require that we import multiple rows from our data source. To import multiple rows in PowerPointWriter, the data marker must be placed in a list entry or table row. see Importing Multiple Rows of Data for more information.
...
Info | ||
---|---|---|
| ||
There is a sample web application page |
- Include the SoftArtisans.OfficeWriter.PowerPointWriter namespace in the code behind
Code Block using SoftArtisans.OfficeWriter.PowerPointWriter;
- In the method that will create the presentation, instantiate the
PowerPointTemplate
object.Code Block PowerPointTemplate pptt = new PowerPointTemplate();
- Open the template file for the presentation.
Code Block pptt.Open(Page.MapPath("//templates//part1_template.pptx"));
- Create a DatabindingProperties object for binding data to the template.
Code Block DataBindingProperties dataProps = pptt.CreateDataBindingProperties();
- Create the 'Company' data source. When importing data with arrays, the values and column names are placed in separate arrays. This first array will contain the column names.
Code Block //The column names are the same as the data markers string[] columnNamesArray = {"Logo"};
- Create a second array that contains the values for the data source. When importing an image, the image value must be placed in a byte array. This can be done by using the File.ReadAllBytes method. See Importing Images for more information.
Code Block Byte[] logoArray = System.IO.File.ReadAllBytes((Page.MapPath("//data//logo.png"))); //Place the image byte[] into an object[] for the BindData call object[] valuesArray = {logoArray};
- Bind the 'Company data to the template. Make sure the data source name is the same as the name used in the template.
Code Block pptt.BindData(valuesArray, columnNamesArray, "Company", dataProps);
- Create the 'Employee' data source. This contains the Employee's name and team
Code Block string[] employeeColNames = {"Name", "Team"}; object[] employeeValues = {"Amy Alberts", "Development"};
- Bind the Employee data to the presentation
Code Block pptt.BindData(employeeValues, employeeColNames, "Employee", dataProps);
- Get the data for the Team data source
To create the DataTable, we will call a helper methodInfo title Following the Sample 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,
GenericParsing.dll
in the bin directory of the projectGetCSVData
is defined in Part1.aspx.cs in aregion
marked Utility Methods.GetCSVData
that parses the CSV files and returns aDataTable
with the values.Code Block DataTable teamData = GetCSVData((Page.MapPath("//data//Team.csv")));
- Bind the Team data to the presentation
Code Block pptt.BindData(teamData, "Team", dataProps);
- Call process to import the data into the template and save the file.
Code Block pptt.Process();
- Stream the output in the response as an attachment
Code Block pptt.Save(Page.Response, "Part1_Output.pptx", false);
Final Code
Code Block |
---|
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);
pptt.Process();
pptt.Save(Page.Response, "Part1_Output.pptx", false);
|
Downloads
You can download the code for the Basic PowerPointWriter Tutorials as a Visual Studio solution, which includes the Project Proposal.
Next Steps
Continue on to Part 2 - The Continue Modifier