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')
core_properties An object that holds presentation file property information such as authors and comments
slide_layouts An instance of SlideLayout that belongs to the first SlideMaster.
slidelayouts not recommended. .slide_layouts is officially recommended.
slide_master The first SlideMaster object.
slidemaster not recommended. .slide_master is officially recommended.
slide_masters SlideMaster list type object.
slidemasters not recommended. .slide_masters is officially recommended.
slide_height The height of the slide. Units are English Metric Units (EMU)
slide_width The width of the slide. Units are English Metric Units (EMU)
slides A _Slides object consisting of slides in a presentation file
save(file) A method to save a presentation file. For the argument, use a file path (string type) or a file object.
It has property information of presentation files such as authors and comments as members.
author string type. Author name.
category string type. Classification of documents such as resumes, proposals and letters.
comments string type. Callout to set in the document.
content_status string type. Document completion status. Example (draft * draft).
created datetime type. Initial creation time of the document.
identifier string type. Some identifier? Example (ISBN)
keywords string type. Keywords used in document search criteria.
language string type. Language used in the document.
last_modified_by string type. The name and email address of the person who last edited the document.
last_printed datetime type. The time when the document was last printed.
modified datetime type. The time when the document was last edited.
revision int type. A revised version of the document that is added each time the document is saved. If you use python-pptx, it will not be added automatically.
subject string type. The theme of the presentation content.
title string type. The title of the presentation.
version string type. Format-free version string.
class pptx.parts.presentation._Slides(sldIdLst, prs) A list of slides in the presentation file.
class pptx.parts.slide.Slide(partname, content_type, element, package=None)
add_chart_part(chart_type, chart_data)[source] A method to add a chart to a slide.
get_image(rId) Get the image with the ID specified by the argument.
get_or_add_image_part(image_file) Returns the image object and its corresponding ID.
name The internal name of the slide.
partname Part name. (Example: /ppt/slides/slide1.xml)
placeholders An instance of the _SlidePlaceholders class. Indicates a placeholder in the slide. http://allabout.co.jp/gm/gc/298109/
shapes An instance of SlideShapeTree. Represents a shape in a slide.
slide_layout Slide layout.
slidelayout not recommended.
.slide_layout is recommended.
■ SlideLayout objects
class pptx.parts.slidelayout.SlideLayout(partname, content_type, element, package=None)
placeholders Placeholders in the slide layout.
shapes Shapes in slide layout.
slide_master Slide master.
slidemaster not recommended. .slide_master is recommended.
■ SlideMaster objects
class pptx.parts.slidemaster.SlideMaster(partname, content_type, element, package=None)
placeholders Placeholders in the slide layout.
shapes Shapes in slide layout.
slide_layouts Slide layout
slidelayouts not recommended. slide_layouts is recommended.
Recommended Posts