Tired of Repetitive Tasks?
How do you handle pasting large numbers of images and tables when creating PowerPoint slides? For example, charts and tables for monthly reports, experimental data analysis results - anything that outputs as images often needs to be pasted into PowerPoint to explain to others.
Until about a year ago, I manually pasted everything, but it was surprisingly time-consuming. When there were small data updates, I had to repeat the same work, which I found incredibly painful.
Especially when the data had only changed slightly, I often thought "Why do I have to spend so much time just for a report?"
To escape this ordeal, I searched for an easier way to paste images and tables into slides, and created a library called PPTemp which I'd like to introduce to you.
Quick Introduction
The pptemp library is a tool for automating the task of pasting images and tables into PowerPoint slides. It can be easily installed via pip. After installation, managing images and tables per slide becomes simple. Just save your images in separate directories for each slide, and they'll be automatically pasted into PowerPoint.
Using this library significantly reduces and streamlines PowerPoint creation work.
GitHub Repository: PPTemp Github repo
Simple Usage Example
# Folder structure
fig
├── 01_First Slide Title
│ ├── 01_Image Label 1-1.png
│ └── 02_Image Label 1-2.png
├── 02_Second Slide Title
│ ├── 01_Image Label 2-1.png
│ └── 02_Image Label 2-2.png
└── 03_Third Slide Title
├── 01_Image Label 3-1.png
├── 02_Image Label 3-2.png
├── 03_Image Label 3-3.png
├── 04_Image Label 3-4.png
├── 05_Image Label 3-5.png
└── 06_Image Label 3-6.png
from pptemp import pptemp
# Initialize class
presentation = pptemp()
# Paste figures for each slide
presentation.add_figure_label_slide()
# Save the presentation
presentation.save("test.pptx")
With this folder structure and just four lines of code, figures are automatically pasted into PowerPoint. "Slide Title" and "Image Label" are automatically added to PowerPoint. Options like "without labels" or "with labels" can be specified.
Detailed Usage
This library is basically a wrapper around the python-pptx library, aiming to automate pasting images and tables into PowerPoint with relatively little code.
1. Installing the Library
The library is registered on pip, so you can install it using the pip command.
pip install pptemp
For the latest version, you can also install from the GitHub repository.
pip install git+https://github.com/Ameyanagi/pptemp
2. Importing the Library
First, import the library.
from pptemp import pptemp
3. Initializing the Class
Next, initialize the pptemp class.
presentation = pptemp()
When specifying an existing slide during initialization, it inherits the template from the existing slide. To change the design, specify template when initializing the pptemp class.
presentation = pptemp(template="template.pptx")
4. Adding Slides
The basic usage is to create slides and add them to presentation.
4.1 Adding Title Slides
Title and content slides are provided. For titles, you can specify the title and subtitle.
slide = presentation.title_slide(title = "Title", subtitle = "Subtitle")
4.2 Adding Content Slides
Content slides can specify a title and content. Content slides create a blank slide with just the slide title.
slide = presentation.content_slide(title = "Slide Title")
4.3 Automatically Adding Slides and Images
The easiest way is to automatically add slides and images. By specifying as follows, slides and images are automatically added.
presentation.add_figure_label_slide(dir_path = "./fig/*/", img_path = "*.png")
5. Editing Slides
5.1 Adding Text
slide = presentation.add_textbox(slide, text = "Text")
5.2 Adding Images
slide = presentation.add_picture(slide, path = "./fig/fig1.png")
5.3 Adding Tables
You can add tables from pandas DataFrames.
slide = presentation.add_table_from_df(slide, df = df, left = 0, top = 12, width = 100, height = 88)
6. Saving Slides
Finally, use the save method to save the slides.
presentation.save(path = "./output.pptx")
Summary
This article introduced how to manipulate PowerPoint with Python. By manipulating PowerPoint, you can create automated reports and presentations. I load this library at the end of my code to automatically generate reports.
Please give it a try!




