Skip to content
Tutorials Center
My learning

Topics

Lesson 37 of 40 ยท Design, Accessibility and Automation

Inside a .pptx File: Open XML, Parts and Automation

A .pptx file is a ZIP of XML parts. See the folder layout, slide XML, relationships and EMU units, and how python-pptx and other tools automate PowerPoint.

A modern PowerPoint file (.pptx) is not a mysterious binary blob. It is a ZIP archive of XML files and media, defined by the Office Open XML standard (ECMA-376 / ISO 29500). Knowing this explains why files can be repaired, why they are small, why other programs can read them, and how automation tools such as the Python library python-pptx, Open XML SDK, or Aspose can create decks without PowerPoint installed.

See it for yourself

Make a copy of a deck, rename it from deck.pptx to deck.zip and open it in any archive tool. You will find something like:

TEXT
[Content_Types].xml
_rels/.rels
docProps/core.xml          title, author, dates
docProps/app.xml           slide count, application
ppt/presentation.xml       slide list, slide size
ppt/_rels/presentation.xml.rels
ppt/slides/slide1.xml      the text and shapes of slide 1
ppt/slides/_rels/slide1.xml.rels
ppt/slideLayouts/slideLayout1.xml
ppt/slideMasters/slideMaster1.xml
ppt/theme/theme1.xml       colors and fonts
ppt/media/image1.png       pictures
ppt/notesSlides/notesSlide1.xml

Each file is called a part. Relationships (.rels files) connect parts: slide1 points to its layout, the layout to the master, the master to the theme, and a slide to its pictures.

flowchart TD
  P["presentation.xml"] --> S1["slide1.xml"]
  S1 --> L["slideLayout1.xml"]
  L --> M["slideMaster1.xml"]
  M --> T["theme1.xml"]
  S1 --> IMG["media/image1.png"]
  S1 --> N["notesSlide1.xml"]

This mirrors the hierarchy in Slide Master basics.

Inside a slide

A slide part holds a shape tree (p:spTree). Each shape (p:sp) has position and size in EMU (914,400 per inch) and a text body made of paragraphs (a:p) and runs (a:r) whose text sits in a:t:

XML
<p:sp>
  <p:nvSpPr><p:cNvPr id="2" name="Title 1" descr="alt text here"/></p:nvSpPr>
  <p:spPr><a:xfrm><a:off x="838200" y="365125"/><a:ext cx="10515600" cy="1325563"/></a:xfrm></p:spPr>
  <p:txBody><a:p><a:r><a:t>Hello deck</a:t></a:r></a:p></p:txBody>
</p:sp>

The name attribute is the Selection Pane name and descr is the alt text. Here a: is the DrawingML namespace and p: the PresentationML one.

Read it with Python

The standard library can open a pptx with zipfile and parse XML with xml.etree.ElementTree. The next examples build a tiny, simplified package in memory (not a complete file that PowerPoint would open) so they run in the browser.

Python List the parts of a mini pptx package

Press Run (or Ctrl + Enter) to see the result here.

Program input ยท what you'd type while the program runs

Type the answers before you press Run, one per line. Each time the program reads a line (with input()), it gets the next line from this box.

Python Extract all slide text

Press Run (or Ctrl + Enter) to see the result here.

Program input ยท what you'd type while the program runs

Type the answers before you press Run, one per line. Each time the program reads a line (with input()), it gets the next line from this box.

Automating without PowerPoint

  • python-pptx (pip install python-pptx): create presentations, add slides from layouts, fill placeholders, add pictures, tables and charts, and read existing decks. It works on any machine, including servers. Typical code: prs = Presentation(); slide = prs.slides.add_slide(prs.slide_layouts[1]); slide.shapes.title.text = "Hello"; prs.save("out.pptx").
  • Open XML SDK (.NET), Apache POI (Java), PptxGenJS (JavaScript) do the same in other languages.
  • Office Scripts / Office.js add-ins run inside PowerPoint on the web.
  • COM automation (win32com from Python) or VBA controls the desktop app (see VBA macros in PowerPoint).

This approach is great for generating many similar decks (a report per customer, one slide per product) from data. The template from Templates and theme files provides the layouts and the library fills them.

Never edit parts by hand in a .pptx unless you keep a backup. A wrong relationship ID or missing content type makes PowerPoint show a "repair" prompt.

Common mistakes

  • Assuming .ppt equals .pptx. The old binary .ppt format (PowerPoint 97-2003) is not a ZIP.
  • Using slide file numbers as slide order. Order comes from presentation.xml, not file names.
  • Forgetting EMU when setting sizes by code.
  • Skipping the template and building every shape by code.

Check your understanding

Quick check ยท 4 questions

of 4 answered You scored / 4 ยท perfect!

  1. 1. What is a .pptx file, technically?

    Open XML packages are ZIP files containing XML parts.
  2. 2. Where is the alt text of a shape stored in slide XML?

    The cNvPr element carries name and descr (alt text).
  3. 3. How many EMU make an inch?

    914,400 EMU per inch; 12,700 EMU per point.
  4. 4. Which tool lets Python create decks without PowerPoint installed?

    python-pptx reads and writes the file format directly.

Summary

  • A .pptx is a ZIP of XML parts joined by relationships.
  • Slides contain shapes with names, alt text and EMU positions.
  • Libraries such as python-pptx generate and read decks without PowerPoint.
  • Use VBA or COM for the running desktop app, file libraries for batch generation.

Next: Project: a pitch deck