当前位置:网站首页>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 》
边栏推荐
- 9. naive Bayes
- [chestnut sugar GIS] global mapper - how to assign the elevation value of the grid to the point
- D. Big Brush
- 云服务器部署 Web 项目
- Solitidy - fallback 回退函数 - 2种触发执行方式
- Unityshader learning notes - Basic Attributes
- Xctf--Web--Challenge--area Wp
- 终端便捷ssh(免密)连接
- unity 扫描圈 圆扩展方法
- How to use js to control the scroll bar of moving div
猜你喜欢

【LeetCode】Easy | 232. Using stack to realize queue (pure C manual tearing stack)

Assembly learning tutorial: accessing memory (3)
![[chestnut sugar GIS] global mapper - how to assign the elevation value of the grid to the point](/img/bb/ea0e78065ba54ff253995faeeb6901.png)
[chestnut sugar GIS] global mapper - how to assign the elevation value of the grid to the point

Basic operations of C language

终端便捷ssh(免密)连接

C语言基础小操作

MySQL advanced (Advanced SQL statement)

动态规划--怪盗基德的滑翔翼

Rotating frame target detection mmrotate v0.3.1 training dota data set (II)

token 过期后,如何自动续期?
随机推荐
AI大模型落地大考,浪潮交出了怎样的答卷?
How to create a CSR (certificate signing request) file?
MySQL advanced (Advanced SQL statement)
聲網,站在物聯網的“土壤”裏
Introduction to Redux: initial experience of Redux
Simple use of qlistview of QT (including source code + comments)
Unity3d get screen width and height
Pyinstaller flash back
Huxiaochun came to fengshu electronics to sign a strategic cooperation agreement with Zoomlion
I have been working as a software testing engineer for 5 years, but I was replaced by an intern. How can I improve myself?
Expansion method of unity scanning circle
Use of OpenCL thread algebra library viennacl
Unity determines whether the UI is clicked
剑指 Offer 22. 链表中倒数第k个节点
Xctf--Web--Challenge--area Wp
Unity obtains serial port data
Attempt to redefine 'timeout' at line 2 solution
【LeetCode】Easy | 225. Using queue to realize stack (pure C manual tearing queue)
Bev instance prediction based on monocular camera (iccv 2021)
Video summary of my station B