from pptx import Presentation
from pptx.util import Pt,Cm
from pptx.dml.color import RGBColor
from pptx.enum.text import MSO_VERTICAL_ANCHOR, PP_PARAGRAPH_ALIGNMENT
from pptx.enum.text import PP_ALIGN
ppt = Presentation()
slide = ppt.slides.add_slide(ppt.slide_layouts[6])
left, top, width, height = Cm(3), Cm(1), Cm(12), Cm(1.2)
textBox = slide.shapes.add_textbox(left=left, top=top, width=width, height=height)
textBoxFill = textBox.fill
textBoxFill.solid()
textBoxFill.fore_color.rgb = RGBColor(187, 255, 255)
line = textBox.line
line.color.rgb = RGBColor(0, 255, 0)
line.width = Cm(0.1)
tf = textBox.text_frame
tf.margin_bottom = Cm(0.1)
tf.margin_left = 0
tf.vertical_anchor = MSO_VERTICAL_ANCHOR.BOTTOM
tf.word_wrap = True
tf.paragraphs[0].text = '这是一段文本框里的文字'
tf.paragraphs[0].alignment = PP_ALIGN.CENTER
tf.paragraphs[0].font.name = '微软雅黑'
tf.paragraphs[0].font.bold = True
tf.paragraphs[0].font.italic = True
tf.paragraphs[0].font.color.rgb = RGBColor(255, 0, 0)
tf.paragraphs[0].font.size = Pt(20)
ppt.save('./办公自动化/files/ppt_test.pptx')