当前位置:网站首页>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 》
边栏推荐
- After reading who moved my cheese
- Xi'an Jiaotong 21st autumn "computerized accounting" online homework answer sheet (I) [standard answer]
- We strongly recommend more than a dozen necessary plug-ins for idea development
- Solitidy - fallback 回退函数 - 2种触发执行方式
- [typescript] defines the return value type of promise
- Set of XXL job principles
- How to write a thesis
- English语法_形容词/副词3级-最高级
- 如何写论文
- Use the code cloud publicholiday project to determine whether a day is a working day
猜你喜欢

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

Solitidy - fallback 回退函数 - 2种触发执行方式

Who is promoting the new inflection point of audio and video industry in 2022?

使用码云PublicHoliday项目判断某天是否为工作日

2022年,谁在推动音视频产业的新拐点?
![[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

网络变压器怎么判断好坏?网络滤波变压器坏了一般是什么症状?

9. naive Bayes

Digital signature——

抓取手机端变体组合思路设想
随机推荐
PKCs 12:personal information exchange syntax v1.1 translation part I
How does WPS cancel automatic numbering? Four options
Finally someone can make the server so straightforward
What indicators should safety service engineers pay attention to in emergency response?
86. separate linked list
聲網,站在物聯網的“土壤”裏
Do you know how to show the health code in only 2 steps
剑指 Offer 18. 删除链表的节点
Rotating frame target detection mmrotate v0.3.1 training dota data set (II)
【LeetCode】Easy | 225. Using queue to realize stack (pure C manual tearing queue)
Is it safe to open an account and trade with a compass?
Rotating frame target detection mmrotate v0.3.1 learning configuration
企事业单位源代码防泄露工作该如何进行
OpenCL线程代数库ViennaCL的使用
El table lazy load refresh
Unity Catmull ROM curve
Answer sheet for online assignment of "motor and drive" of Xijiao 21 autumn (IV) [standard answer]
Database SQL language 06 single line function
Visualization of 3D geological model based on borehole data by map flapping software
Projet Web de déploiement du serveur Cloud