Skip to content

Latest commit

 

History

History
85 lines (54 loc) · 2.18 KB

PowerPoint_Add_Slide_With_Textbox.md

File metadata and controls

85 lines (54 loc) · 2.18 KB



Template request | Bug report | Generate Data Product

Tags: #powerpoint #slide #portrait #pptx #snippet

Author: Florent Ravenel

Description: This notebook allows users to create a new slide in PowerPoint with a textbox.

Input

Import libraries

try:
    from pptx import Presentation
except:
    !pip install python-pptx --user
    from pptx import Presentation
from pptx.util import Inches, Pt

Setup Variables

output_pptx = "MyPowerPoint_Slide_Textbox.pptx"
text1 = "This is text inside a textbox"
text2 = "This is a second paragraph that's bold"
text3 = "This is a third paragraph that's big"

Model

Create Presentation Obj

prs = Presentation()

Setup Width & Height (Portrait)

prs.slide_height = Inches(11.69)
prs.slide_width = Inches(8.27)

Setup Layout

blank_slide_layout = prs.slide_layouts[6]

Add slide with textbox

slide = prs.slides.add_slide(blank_slide_layout)

left = top = width = height = Inches(1)
txBox = slide.shapes.add_textbox(left, top, width, height)
tf = txBox.text_frame

tf.text = text1

p = tf.add_paragraph()
p.text = text2
p.font.bold = True

p = tf.add_paragraph()
p.text = text3
p.font.size = Pt(40)

Output

Save presentation

prs.save(output_pptx)