Page tree

Versions Compared

Key

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

...

  1. Include the SoftArtisans.OfficeWriter.PowerPointWriter namespace in the code behind
    Code Block
    using SoftArtisans.OfficeWriter.PowerPointWriter;
    
  2. In the method that will create the presentation, instantiate the PowerPointTemplate object.
    Code Block
    PowerPointTemplate pptt = new PowerPointTemplate();
    
  3. Open the template file for the presentation.
    Code Block
    pptt.Open(Page.MapPath("//templates//part1_template.pptx"));
    
  4. Create a DatabindingProperties object for binding data to the template.
    Code Block
    DataBindingProperties dataProps = pptt.CreateDataBindingProperties();
    
  5. 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"};
    
  6. 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};
    
  7. 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);
    
  8. Create the 'Employee' data source. This contains the Employee's name and team
    Code Block
    string[] employeeColNames = {"Name", "Team"};
    object[] employeeValues = {"Amy Alberts", "Development"};
    
  9. Bind the Employee data to the presentation
    Code Block
    pptt.BindData(employeeValues, employeeColNames, "Employee", dataProps);
    
  10. Get the data for the Team data source
    Info
    titleFollowing 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 project GetCSVData is defined in Part1.aspx.cs in a region marked Utility Methods.

    These calls are to To create the DataTable, we will call a helper method GetCSVData that parses the CSV files and returns a DataTable with the values.
    Code Block
    DataTable teamData = GetCSVData((Page.MapPath("//data//Team.csv")));
    
  11. Bind the Team data to the presentation
    Code Block
    pptt.BindData(teamData, "Team", dataProps);
    
  12. Call process to import the data into the template and save the file.
    Code Block
    pptt.Process();
    
  13. Stream the output in the response as an attachment
    Code Block
    pptt.Save(Page.Response, "Part1_Output.pptx", false);
    

...