There is something like pasting one image on each PowerPoint slide to make a work procedure manual. It's a transcendental simple task, but it takes a long time. It's a simple repetitive task, so I'd like to automate it using the code that was rolling on the net.
Automatically create PowerPoint materials with one image attached to each slide.
I would like to create a character introduction slide for a certain anime that I like. The composition is Cover → Image → Character description → Image → Character description →… (Hereafter, the image and character description are alternated) It is said. The slides automatically created using the code created this time will be introduced at the end.
python3.7.2 Windows10
ppt.py
import pptx
from pptx.util import Inches
from pptx import Presentation
from glob import glob
ppt = Presentation()
width = ppt.slide_width
height = ppt.slide_height
#Types of slides to use
title_slide_layout = ppt.slide_layouts[0] #Creating a Title Slide
bullet_slide_layout = ppt.slide_layouts[1] #Creating Title and Content
blank_slide_layout = ppt.slide_layouts[6] #Creating a blank
#Title Slide
slide = ppt.slides.add_slide(title_slide_layout)
title = slide.shapes.title
subtitle = slide.placeholders[1]
title.text = "○○ Description"
subtitle.text = "kokoro pyonpyon"
#Preparing to paste the image on Blank
fnms = glob('figures/*.JPG')
tx_left = tx_top = tx_width = tx_height = Inches(1)
i = 1
for fnm in fnms:
#Put the image on Blank
slide_picture = ppt.slides.add_slide(blank_slide_layout)
pic = slide_picture.shapes.add_picture(fnm, width/4,height/2, width/2, height/2)
#Then insert a text box in the empty space
txBox = slide_picture.shapes.add_textbox(tx_left, tx_top, tx_width*15, tx_height)
tB = txBox.text_frame
tB.text = "Name: "
#Creating Title and Content
slide_description = ppt.slides.add_slide(bullet_slide_layout)
shapes = slide_description.shapes
title_shape = shapes.title
body_shape = shapes.placeholders[1]
#Write title and text in Title and Content
title_shape.text = 'Character description ' + str(i)
tf = body_shape.text_frame
tf.text = 'She works at '
i += 1
ppt.save('figure.pptx')
pptx
_ A Python library that creates and updates PowerPoint files (.pptx). Typical uses include creating a customized PowerPoint document from a database or making it available for download by clicking a link on a web application. It is also possible to automatically create an engineering status report in a reportable format that summarizes information on the business management system. Sometimes I update my presentation library all at once, or automatically create one or two slides that I'm tired of working on. _
(Part of this material is translated literally.)
Well, it's enough if you know this easily. Perhaps. The brief meaning of each command is commented in the code.
Enter the details manually for each slide. Most of it is created automatically, so it should be a lot of labor saving.
How to install the library.
$ pip install numpy
Like. Somehow I made it numpy.
python-pptx Getting Started Paste image files in PowerPoint with Python
Recommended Posts