如何让Powerpoint自动调整文本

时间:2015-08-22 20:15:35

标签: python powerpoint

是否可以让Powerpoint 2013正确自动调整文本?我使用的是python-pptx,我可以设置自动调整选项,但它最初不起作用。如果我调整文本框的大小或随后更改像" wrap"然后汽车配件工作。但是,我无法从python-pptx那样做。我需要在第一次添加文本时使用该选项。

我认为这是PowerPoint中的一个错误,微软并不打算修复它,但希望我错了。

1 个答案:

答案 0 :(得分:2)

这是一个简单的代码,它将文本包装在文本框架中,而无需调整文本框的大小。我希望这会有所帮助。

from pptx import Presentation
from pptx.util import Inches

prs = Presentation()
titleLayout = prs.slide_layouts[0]
slide = prs.slides.add_slide(titleLayout)

textBox = slide.shapes.add_textbox(Inches(3.5), Inches(0.5),Inches(3), Inches(3.0))
textFrame = textBox.text_frame
textFrame.word_wrap = True
textParagraph = textFrame.add_paragraph()
textParagraph.text = "This is a word_wrap example. The words  are wrapped within the textframe"

prs.save("C:\OSGeo4W\GPSPictureManager\Tests\PptxWordWrapTest.pptx")#specify path for new pptx file

更多详情可在http://python-pptx.readthedocs.io/en/latest/api/text.html#textframe-objects

中找到