Community Spring Cleaning week is here! Join your fellow Maveryx in digging through your old posts and marking comments on them as solved. Learn more here!

Alteryx Designer Desktop Discussions

Find answers, ask questions, and share expertise about Alteryx Designer Desktop and Intelligence Suite.
SOLVED

Using Template PowerPoint file and output PowerPoint depending on different projects

knozawa
11 - Bolide

Hello,

 

I'm looking to output a PowerPoint using a PowerPoint template depending on different projects. 

Only a few fields will be updated in the PowerPoint slides based on upstream data.

I thought about using a reporting tools, but it seems like I cannot input a PowerPoint as a template input file, so modifying XML file would be a better choice in Alteryx.

 

There was a similar conversation in the Alteryx community forum: https://community.alteryx.com/t5/Alteryx-Designer-Discussions/Auto-populate-powerpoint-template-with...

If I'm understanding it correctly, this approach is to:

1. extract the PowerPoint to xml first

2. modify the xml file in Alteryx using the upstream data

3. Alteryx will produce the modified XML file, not PowerPoint

4. use the modified XML for different projects

 

I tried to follow what they've done using the XML input file, so I used a 7zip to extract the PowerPoint and it produced many xml files.  However, I was not sure which XML file was the one that contained actual content in the slide deck to modify.  Does anyone know which one to use?  Also, if there is a better way to accomplish this, I appreciate any inputs!

knozawa_0-1629072278282.png

 

Sincerely,

knozawa

16 REPLIES 16
kelly_gilbert
13 - Pulsar

Hi, @knozawa - the XML files you want to edit are in the ppt --> slides folder. Inside \ppt\slides, you'll find a separate XML file for each slide in your presentation (slide1.xml, slide2.xml, etc.)

 

I use this method myself, and it works well. I'll be interested to see if there are other ideas for accomplishing this!

 

The general method is:

  1. Create a PowerPoint template with placeholders for each value you want to replace (e.g. if your fieldname is open_roles, then insert {{open_roles}} in the appropriate place in the PowerPoint slide.
  2. Unzip the template pptx file
  3. Read in the XML file (for example, if you want to edit slide #3, then input ppt\slides\slide3.xml)
  4. Modify the slide XML by replacing your placeholder text with the field value
  5. Output the updated slide XML (for example, if you are modifying slide #3, then output ppt\slides\slide3.xml -- you are replacing the original slide3.xml with the modified version)
  6. Re-zip the files and save the zip file with a .pptx extension
knozawa
11 - Bolide

@kelly_gilbert ,

 

Thank you for your detailed reply!

 

I followed your instruction and have questions:

 

Q1. When you replaced the value, did you replace whole thing {{open_roles}} to sales for example (meaning the {{}} will be removed in the modified xml file)?

 

Q2. At the last step, did you re-zip the whole folder that contained all the xml files using 7zip or just compressed (zipped) folder from the file explorer directly?  I tried both ways and changed the .zip to .pptx.  When I tried to open the PowerPoint, it showed an error message:"PowerPoint found unreadable content in ...There was an error accessing...".

 

 

kelly_gilbert
13 - Pulsar

Q1 - Correct - replace the whole thing, including the brackets, like replace([your_xml_field], "{{sales}}", tostring([your_sales_field]))

The curly brackets are there to identify the placeholders in your template vs. other text in your template. For example, the word "sales" could occur in the title of your slide, so you don't want to replace that. We only want to replace sales when it is surrounded by curly brackets.

 

 

Q2 - correct, zip all of the files (including [Content Types].xml) into a new zip file, and make sure that the folder structure (_rels, customXml, etc.) is present in your zip file.

kelly_gilbert_0-1629148804545.png

 

I haven't tried using 7zip to create the zip file, but I don't see any reason why that wouldn't work. I'm using Python zipfile to create my zip file, but I have also done it manually from the File Explorer, which also works.

 

One other issue that could cause that error is when the replacement text has certain characters in it (XML predefined entities, such as & " ' < >). You will need to replace those with their name (e.g. "&amp;" for ampersand or "&lt;" for <).

For example, say you have the placeholder {{department_name}}, and the actual department_name is Planning & Analytics. Inserting Planning & Analytics in the XML will cause an error due to the ampersand (&). You can fix it by replacing the & with the character name, "&amp;"
Example: replace([your_xml_field], "&", "&amp;")

 

It will appear as "Planning &amp; Analytics" in the raw XML, but it will appear as "Planning & Analytics" in PowerPoint.

kelly_gilbert
13 - Pulsar

Two other things to check:

  • Make sure that your output file has the exact same name and location as the original. For example, if you are editing ppt\slides\slide2.xml, make sure that your output tool is outputting to the exact same folder/file name.
  • Make sure that your Output Data tool is not outputting any additional characters that would make the XML invalid. Make sure that First Row Contains Field Names is NOT checked, and make sure that the delimiter is something that won't occur in your XML file ("\0" is a good delimiter to use).
  • Make sure that the Code Page on your output is UTF-8

 

If you're still having issues, please share an example of your workflow with some fake data, as well as your .pptx template, so we can take a look at what might be happening!

knozawa
11 - Bolide

@kelly_gilbert 

Thank you for your help!  I still have issue opening the corrupted PowerPoint.

I wanted to attach the PowerPoint and Zip folder, but it seems like there is a restriction on uploading those file types in the Alteryx Community forum.

 

Here is the screenshot:
1. original PowerPoint ("DELETE.pptx")
Screen Shot 2021-08-17 at 9.06.10 AM.pngScreen Shot 2021-08-17 at 9.06.21 AM.png

 

2. {{delete}} was updated to DELETEDELETE in slide1.xml

Screen Shot 2021-08-17 at 9.06.59 AM.png

 

3. The DELETE zipped folder's extension was updated to .pptx ("DELETE (2).pptx")

Screen Shot 2021-08-17 at 9.07.42 AM.pngScreen Shot 2021-08-17 at 9.07.50 AM.png

knozawa
11 - Bolide

@kelly_gilbert 

I also tested without modifying the slide1.xml file and re-zipped the DELETE folder and renamed .zip to .pptx.
Same error occurred.

kelly_gilbert
13 - Pulsar

That was a great idea to test rezipping the file without modifying it! That tells us the problem is with the zip and not the XML. Are you possibly zipping the outer folder?

Make sure that you're just zippng the _rels, ppt, etc. folders, and the [Content_Types].xml file, and not the folder that contains them.

 

ppt zip.gif

knozawa
11 - Bolide

@kelly_gilbert 

Thank you very much!  I was creating zip file using the DELETE folder instead of zippng the _rels, ppt, etc. folders, and the [Content_Types].xml file.

If you have any tips on your process, could you please tell me:
1. When there are multiple projects to update the PowerPoint using the template, do you manually create the unzipped folder?
2. Do you embed the python code into the python tool in the alteryx workflow to zip the files and rename it to .pptx?

kelly_gilbert
13 - Pulsar

I'm so glad you got it working!

 

Q1 - I use Python to unzip the file as well as re-zip it after edits. I just finished converting the full edit process to Python, so my current workflow is:

  1. Use standard Alteryx tools to combine, summarize, and reshape the data
  2. Feed the final data into a Python tool
  3. In the Python tool:
    • Unzip the .pptx template
    • Make the text replacements
    • Re-zip the .pptx template

However, if you want to use standard Alteryx tools for the text replacement, you could either use two Python tools (Python tool to unzip file --> replace text in Alteryx --> Python tool to re-zip file).

 

You can also use the Run Command tool with 7Zip to un-zip and re-zip the files.

 

One more idea: if you only have to edit specific slides, you don't have to unzip the file. You can import the slide XML directly using an Alteryx Input Data tool (select the .pptx file, then choose .zip as the file format, then click on File in Archive to select your slide XML file).
Then, once you've made your replacements, write out the new XML file to a temp directory.

Then, use Run Command to update the .zip file by adding the newly changed files (update command from the 7zip manual: http://7zip.bugaco.com/7zip/MANUAL/cmdline/commands/update.htm)

Note that this will modify the original zip file, so you will want to keep an extra copy of your blank template! Or, use a .bat file to copy the template .pptx first, and then update the copy.

 

Labels