Page tree

Versions Compared

Key

  • This line was added.
  • This line was removed.
  • Formatting was changed.

...

Info
titleFollowing the Sample Code

There is a sample web application page Part1.aspx and code behind Part1.aspx.cs available in the ProjectProposal/templates/part1_template.pptx directory that shows the completed code.

...

  1. Include the SoftArtisans.OfficeWriter.PowerPointWriter namespace in the code behind
Code Block
using SoftArtisans.OfficeWriter.PowerPointWriter;

...

  1. In the method that will actually create the presentation, instantiate the PowerPointTemplate object.
Code Block
PowerPointTemplate pptt = new PowerPointTemplate();

...

  1. Open the template file for the presentation.
    Code Block
    
    pptt.Open(Page.MapPath("//templates//part1_template.pptx"));
    

...

  1. Create a DatabindingProperties object for binding data to the template.
    Code Block
    
    DataBindingProperties dataProps = pptt.CreateDataBindingProperties();
    

...

  1. Create an array to hold the values that will appear in the presentation.
Code Block
//The values to display
//This presentation is for a project proposal for a surgery scheduling software
object[] valuesArray = { "Surgery Schedule", "January 1, 2014", "Under Review", "Pamela Blythe", "January 1, 2015", "6 months", "Software to schedule surgeries that require multiple resources such as surgeons, assistants, nurses, pre-op and post-op space, surgery theater, long-term recovery rooms." };

...

  1. Create a second array that contains the column names. The column names values must match the data markers in the template.
    Code Block
    
    //The column names are the same as the data markers
    string[] columnNamesArray = { "Name", "Date", "ReviewStatus", "Leader", "Start", "Estimate", "Summary" };
    

...

  1. Bind the 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, "Proposal", dataProps);
    

...

  1. 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
    pptt.Save(Page.Response, "Part1_Output.xlsx", false);
    

Final Code

Code Block
PowerPointTemplate pptt = new PowerPointTemplate();
pptt.Open(Page.MapPath("//templates//part1_template.pptx"));
DataBindingProperties dataProps = pptt.CreateDataBindingProperties();
object[] valuesArray = { "Surgery Schedule", "January 1, 2014", "Under Review", "Pamela Blythe", "January 1, 2015", "6 months", "Software to schedule surgeries that require multiple resources such as surgeons, assistants, nurses, pre-op and post-op space, surgery theater, long-term recovery rooms." };
string[] columnNamesArray = { "Name", "Date", "ReviewStatus", "Leader", "Start", "Estimate", "Summary" };
pptt.BindData(valuesArray, columnNamesArray, "Proposal", dataProps);
pptt.Process();
pptt.Save(Page.Response, "Part1_Output.xlsx", false)

...