python - pptx

from pptx import Presentation
from pptx.util import Pt
from docx.shared import Inches

prs=Presentation()
slide=prs.slides.add_slide(prs.slide_layouts[1])
shape_txt=slide.shapes.placeholders
shape_txt[0].text='this is title'
shape_txt[1].text='this is sub title'
new_para=shape_txt[1].text_frame.add_paragraph()

def para_set(new_para,txt,level=1,size=22,bold=False,italic=False,underline=False):
new_para.text = txt
new_para.level = level
new_para.font.size = Pt(size)
new_para.font.bold = bold
new_para.font.italic = italic
new_para.font.underline = underline
def add_txt_box(slide,txt,left,top,width,height):
textbox=slide.shapes.add_textbox(left,top,width,height)
textbox.text=txt
new_para=textbox.text_frame.add_paragraph()
new_para.text="This is a second paragraph!"
def add_pic(slide,pic,left,top,width,height):
slide.shapes.add_picture(pic,left,top,width,height)
table=slide.shapes.add_table(2,3,Inches(3.5),Inches(4.5),Inches(5),Inches(1))
para_set(new_para,'新段落')
add_txt_box(slide,'new text',Inches(4),Inches(1.8),Inches(5),Inches(1))
add_pic(slide,'123.png',Inches(1),Inches(4.5),Inches(2),Inches(2))
prs.save('test.pptx')

转载于:https://www.cnblogs.com/xiesongyou/p/7922750.html

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值