当前位置:网站首页>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 》
边栏推荐
- Introduction to mmcv common APIs
- Uboot reads the DDR memory size by sending 'R' characters through the terminal
- Why can transformer break into the CV world and kill CNN?
- Database SQL language 04 subquery and grouping function
- [Motrix] download Baidu cloud files using Motrix
- ECS deployment web project
- 抓取手机端变体组合思路设想
- /Path/to/ idiom, not a command
- El table lazy load refresh
- How does WPS cancel automatic numbering? Four options
猜你喜欢

Terminal convenient SSH connection

Remote sensing image /uda:curriculum style local to global adaptation for cross domain remote sensing image segmentation

Introduction to mmcv common APIs

Why can transformer break into the CV world and kill CNN?

VFPBS在IIS下调用EXCEL遇到的Access is denied

Solidy - fallback function - 2 trigger execution modes

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

9. naive Bayes
![[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

86. 分隔链表
随机推荐
Uboot reads the DDR memory size by sending 'R' characters through the terminal
如何写论文
VFPBS上传EXCEL并保存MSSQL到数据库中
[typescript] cannot redeclare block range variables
[typescript] experimentaldecorators of vscode stepping pit
Rotating frame target detection mmrotate v0.3.1 learning configuration
Sound net, debout dans le "sol" de l'IOT
VFPBS在IIS下调用EXCEL遇到的Access is denied
Set a plane to camera viewport
Qt之QListView的简单使用(含源码+注释)
1380. lucky numbers in matrices
Introduction to Redux: initial experience of Redux
终端便捷ssh(免密)连接
Use the code cloud publicholiday project to determine whether a day is a working day
旋转框目标检测mmrotate v0.3.1入门
Solitidy - fallback 回退函数 - 2种触发执行方式
The average salary of software testing in 2022 has been released. Have you been averaged?
What do you think of the deleted chat records? How to restore the deleted chat records on wechat?
El table lazy load refresh
Answer sheet for online assignment of "motor and drive" of Xijiao 21 autumn (IV) [standard answer]