python - pptx

Posted 沧海一粒水

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了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‘)





























以上是关于python - pptx的主要内容,如果未能解决你的问题,请参考以下文章

Python代写,Python作业代写,代写Python,代做Python

Python开发

Python,python,python

Python 介绍

Python学习之认识python

python初识