当前位置:网站首页>Learning automation ppt
Learning automation ppt
2022-06-30 05:44:00 【翀-】
List of articles
from pptx import Presentation
from pptx.util import Inches
from pptx.enum.shapes import MSO_SHAPE
Quick creation PPT
# PPT object
ppt = Presentation()
# Traverse all layouts
for layout in ppt.slide_layouts:
# For the sake of PPT File add slides using a certain layout
ppt.slides.add_slide(layout)
# preservation PPT file
ppt.save('./output/show_all_layout.pptx')
Insert text into the slide
ppt = Presentation()
# Slide layout , Select the first default layout
slide_layout = ppt.slide_layouts[0]
# slide Object is one slide , One PPT There can be multiple slides in the file
slide = ppt.slides.add_slide(slide_layout)
# Take the... Of this slide title Place holder
title = slide.shapes.title
# towards title Insert text into the text box
title.text = ' I'm the title '
# Take the second text box of this slide
subtitle = slide.placeholders[1]
# Insert text into the second text box
subtitle.text = ' Body box '
# Add a second slide , Take a different layout
slide_layout = ppt.slide_layouts[1]
slide = ppt.slides.add_slide(slide_layout)
# Insert text into the second slide in the same way
title = slide.shapes.title
title.text = ' I'm the title 2'
subtitle = slide.placeholders[1]
subtitle.text = ' Body box 2'
ppt.save('./output/write_text.pptx')
- Another way is that it can completely give placeholder objects to PPT File insert text , The code is as follows :
# establish PPT object
ppt = Presentation()
# Choose a layout
layout = ppt.slide_layouts[0]
# Add slides
slide = ppt.slides.add_slide(layout)
# Get all placeholders in this slide
placeholders = slide.shapes.placeholders
# Insert text
placeholders[0].text = ' First text box '
placeholders[1].text = ' The second text box '
# Save the file
ppt.save('./output/write_text2.pptx')
- How to append new text to existing text ?
# Read in existing PPT file
ppt = Presentation('./output/write_text.pptx')
# First slide
slide0 = ppt.slides[0]
# Get all placeholders for the first slide
placeholder = slide0.shapes.placeholders
# Add a new paragraph to the second placeholder object
new_paragraph = placeholder[1].text_frame.add_paragraph()
# Append new text
new_paragraph.text = ' Additional new text '
ppt.save('./output/write_text3.pptx')
Insert a new text box into the slide
ppt = Presentation()
# Blank layout
layout = ppt.slide_layouts[6]
# Add a slide with a blank layout
slide = ppt.slides.add_slide(layout)
# Preset position and size
# Preset position and size
left = Inches(5)
top = Inches(5)
width = Inches(5)
height = Inches(5)
# left、top Is the relative position ,width、height Is the size of the text box
textbox = slide.shapes.add_textbox(left,top,width,height)
textbox.text = ' This is a new text box '
# Add a new paragraph
new_paragraph = textbox.text_frame.add_paragraph()
new_paragraph.text = ' The second paragraph in the text box '
ppt.save('./output/add_new_text.pptx')
Insert picture into slide
# Instantiation PPT object
ppt = Presentation()
# Blank layout
layout = ppt.slide_layouts[6]
# Add slides
slide = ppt.slides.add_slide(layout)
# Define where to add the picture
left = Inches(0)
top = Inches(0)
# Define the size of the inserted picture
width = Inches(2)
height = Inches(2)
img_path = './input/01.jpg'
# Insert picture into slide
pic = slide.shapes.add_picture(img_path,left,top,width,height)
ppt.save('./output/add_image.pptx')
Insert shapes into slides
ppt = Presentation()
layout = ppt.slide_layouts[6]
slide = ppt.slides.add_slide(layout)
# Define where to insert the shape
left = Inches(1)
top = Inches(2)
# Define the size of the shape to insert
width = Inches(1.8)
height = Inches(1)
# Insert shape
shape = slide.shapes.add_shape(MSO_SHAPE.PENTAGON,left,top,width,height)
# Add text to shapes
shape.text = ' First step '
for i in range(2,6):
# Mobile location
left = left + width - Inches(0.3)
# Insert shape
shape = slide.shapes.add_shape(MSO_SHAPE.CHEVRON,left,top,width,height)
shape.text = f' The first {
i} Step '
ppt.save('./output/add_shape.pptx')
ppt = Presentation()
# Define the size of the inserted picture
width = Inches(5)
height = Inches(5)
for member in MSO_SHAPE.__members__:
try:
layout = ppt.slide_layouts[6]
slide = ppt.slides.add_slide(layout)
# Add shape
shape = slide.shapes.add_shape(member.value,left,top,width,height)
shape.text = member.name
except:
# The content of the line after the error is reported
print(member.name,member.value)
ppt.save('./output/show_all_layout.pptx')
NO_SYMBOL NO_SYMBOL (19)
Insert table
ppt = Presentation()
layout = ppt.slide_layouts[6]
slide = ppt.slides.add_slide(layout)
rows = 2
cols = 2
left = Inches(3.5)
top = Inches(4.5)
width = Inches(6)
height = Inches(0.8)
# Add table , Get table class
table = slide.shapes.add_table(rows,cols,left,top,width,height).table
# First column width
table.columns[0].width = Inches(2.0)
# The second example is width
table.columns[1].width = Inches(4.0)
table.cell(0,0).text = ' First row, first column '
table.cell(0,1).text = ' The first line, the second column '
table.cell(1,0).text = ' First row, first column '
table.cell(1,1).text = ' The second line, the second column '
ppt.save('./output/add_table.pptx')
Reference resources 《Python Office automation 》
边栏推荐
- AI大模型落地大考,浪潮交出了怎样的答卷?
- Why can transformer break into the CV world and kill CNN?
- Xctf attack and defense world crypto advanced area
- Unity Catmull ROM curve
- 1380. lucky numbers in matrices
- After reading who moved my cheese
- Is it safe to open an account and trade with a compass?
- 企事业单位源代码防泄露工作该如何进行
- Digital signature——
- Learning about functions QAQ
猜你喜欢

86. separate linked list

Use the code cloud publicholiday project to determine whether a day is a working day

Idea of capturing mobile terminal variant combination

What do you think of the deleted chat records? How to restore the deleted chat records on wechat?

Visualization of 3D geological model based on borehole data by map flapping software

Sword finger offer 22 The penultimate node in the linked list

Did you know that WPS can turn on eye protection mode?

图扑软件基于钻孔数据的三维地质模型可视化

About modifying dual system default startup item settings

Redistemplate common method summary
随机推荐
[untitled] user defined function
On line assignment of financial cost management in the 22nd spring of Western Polytechnic University [Full Score answer]
聲網,站在物聯網的“土壤”裏
9. naive Bayes
Baiwen.com 7 days Internet of things smart home learning experience punch in the third day
Set of XXL job principles
English语法_形容词/副词3级-最高级
Redistemplate common method summary
旋转框目标检测mmrotate v0.3.1 训练DOTA数据集(二)
Online assignment of C language program design in the 22nd spring of Western Polytechnic University
Unity3d get screen width and height
Xctf attack and defense world crypto advanced area
剑指 Offer 22. 链表中倒数第k个节点
C语言基础小操作
企事业单位源代码防泄露工作该如何进行
[Blue Bridge Road -- bug free code] analysis of AT24C02 storage code
How to use js to control the scroll bar of moving div
Array pointers and pointer arrays
Fifty years ago, the go code first submitted by the inventor of Hello world was as long as this
Delete the repeating elements in the sorting list (simple questions)