python-pptx summary

■ What is python-pptx?

A python library that can create pptx (presentation format files). The following is an excerpt from the API Documentation of Official.

# -*- coding: utf-8 -*-

from pptx import Presentation

SLD_LAYOUT_TITLE_AND_CONTENT = 0

#Create a Presentation instance
#C by default:\Python27\Lib\site-packages\pptx\templates\default.Read pptx
prs = Presentation()

#Layout decision
slide_layout = prs.slide_layouts[SLD_LAYOUT_TITLE_AND_CONTENT]

#Create slides(Slide)
slide = prs.slides.add_slide(slide_layout)
##Text settings(placeholders)
slide.shapes.title.text = "placeholders[0]"
slide.placeholders[1].text = "placeholders[1]"
print type(slide)
print "len(slide.placeholders) : " + str(len(slide.placeholders))
print slide.placeholders[0].text
print slide.placeholders[1].text
print

print type(slide.shapes.placeholders[1].text_frame)
print slide.shapes.placeholders[0].text_frame.text
print slide.shapes.placeholders[1].text_frame.text

###Add text inside placeholder(TextFrame)
text_frame = slide.shapes.placeholders[1].text_frame
paragraph = text_frame.add_paragraph()
paragraph.text = "add_paragraph text"
####Paragraph level
paragraph.level = 1

paragraph = slide.shapes.placeholders[1].text_frame.add_paragraph()
paragraph.text = "add_paragraph text2"
paragraph.level = 8

text_frame.fit_text(font_family='Calibri', max_size=33, bold=True, italic=True, font_file=None)

###Remove placeholder
#text_frame.clear()

#Add slide
slide = prs.slides.add_slide(slide_layout)
##Text settings
slide.shapes.title.text = "placeholders[0]"
slide.placeholders[1].text = "placeholders[1]"

#Save slides
prs.save('python.pptx')

■ Presentation object

■ CoreProperties object

It has property information of presentation files such as authors and comments as members.

■ _Slides (sldIdLst, prs) object

class pptx.parts.presentation._Slides(sldIdLst, prs) A list of slides in the presentation file.

■ Slide object

class pptx.parts.slide.Slide(partname, content_type, element, package=None)

.slide_layout is recommended.

■ SlideLayout objects

class pptx.parts.slidelayout.SlideLayout(partname, content_type, element, package=None)

■ SlideMaster objects

class pptx.parts.slidemaster.SlideMaster(partname, content_type, element, package=None)

Recommended Posts

python-pptx summary
Python Summary
Django Summary
Linux Summary
Python summary
Django Summary
pyenv summary
String summary 1
pytest summary
matplotlib summary
AtCoderBeginnerContest180 Review & Summary
Kaggle Summary: Outbrain # 2
LINQ library summary
Sphinx setup summary
AtCoderBeginnerContest181 Review & Summary
Digital technology summary
AtCoderBeginnerContest182 Review & Summary
Python tutorial summary
blockdiag grammar summary
AtCoderBeginnerContest183 Review & Summary
Linux Command Summary
AtCoderBeginnerContest179 Review & Summary
Kaggle Summary: Outbrain # 1
update, upgrade summary
Standard input summary
Django filter summary
python related summary
2020 IT Conference Summary
Visualize summary statistics
pytest usage summary
Docker command summary
Python basics summary
Kaggle related summary