Send Close Add comments: (status displays here)
Got it!  This site "robinsnyder.com" uses cookies. You consent to this by clicking on "Got it!" or by continuing to use this website.  Note: This appears on each machine/browser from which this site is accessed.
Python: OpenXML pptx files
by RS  admin@robinsnyder.com : 1024 x 640


1. Python: OpenXML pptx files
Python can be used to both create and read pptx files in the OpenXML data format. The Python python-pptx package will be used.

One way to install the python-pptx package is as follows.
D:\Python38\Scripts\pip3.exe install python-pptx

Use the path to your installed version of Python.

2. Getting started
Besides this page, more information on getting started is at the python-pptx web site at https://python-pptx.readthedocs.io/en/latest/user/quickstart.html.

3. Slides
PowerPoint is based on slides of various forms which one customizes as needed.

It is easier to use the pre-built slide forms rather than create your own. To create your own, start with a blank slide and add content.

4. Quirks
For historical reasons, PowerPoint has many specific ways to do things that may not be obvious.

There are some things that are difficult or impossible to do with PowerPoint. One can always generate an image and use that image to do such things. There are also certain specific things that cannot be done using python-pptx.

For such things (e.g., custom sounds and delays, etc.) I use VBA (Visual Basic for Applications) code in PowerPoint to do the fix-ups.

5. Slide size
Whenever possible, I have found it useful to adjust the exact size of the slides to match the size of the projector that I will be using. This avoids having extra "black" space around the slide.

You may have to experiment to get the best size but the aspect ratio (width to height) is important.

6. Charts
PowerPoint supports charts to a limited extent, but I have found it generally useful to create the desired image of the chart (e.g., via matplotlib) and then include that image.

For a real world financial printing system, we ended up using high resolution chart images generated using the existing process and then hooked those images into the generated presentations.

7. Microsoft OpenXML SDK
Microsoft has on OpenXML SDK that allows one to deconstruct an OpenXML file into the C# code that would generate that OpenXML file using the OpenXML SDK.

This C# code can then be studied in order to obtain the necessary patterns with which to generate the desired documents. Here is the Python code [#1]

Here is the output of the Python code.


8. Locked files
Note that PowerPoint (and other programs) will lock the file currently loaded into the application.

If you try to generate a pptx file while PowerPoint has it locked, a run-time error results.

9. Points
In the printing industry: Fonts are often sized by points.

10. End of page

by RS  admin@robinsnyder.com : 1024 x 640