更改PowerPoint文本框大小



我正在尝试更改text_frame的大小,以匹配我正在自动创建的PowerPoint幻灯片的大小。我发现我可以通过…更改幻灯片宽度和高度。。。

prs=Presentation()
prs.slide_width = Inches(16)
prs.slide_height = Inches(9)

标题形状通过。。。

title_shape = shapes.title
title_shape.width = Inches(16)
title_shape.height = Inches(2)

但是这个方法对使用以下代码的text_frame没有任何影响。。。

slide = prs.slides.add_slide(bullet_slide_layout)
shapes = slide.shapes
title_shape = shapes.title
title_shape.width = Inches(16)
title_shape.height = Inches(2)
body_shape = shapes.placeholders[1]
title_shape.text = project['name']
tf = body_shape.text_frame
tf.text = ""
tf.width = Inches(16)
tf.height = Inches(9)

我以为tf.widthtf.height会起作用,但对我不起作用。有什么想法吗?

PowerPoint幻灯片上有大小的东西是形状。标题占位符是一个形状(基本上是文本框形状(,正文占位符也是。

因此,要更改其大小,请指定形状的宽度和高度属性:

body_shape = shapes.placeholders[1]
body_shape.width = Inches(16)
body_shape.height = Inches(9)

某些形状(称为自动形状的几何图形(可以包含文本。其他形状,如图片形状不能。当形状可以包含文本时,该形状具有.text_frame属性,该属性是"文本";容器";形状的文本,并控制其格式化的某些方面,如是否包装等。

但文本框本身并没有大小;文本框的大小取决于它所属形状的大小,在一定程度上取决于换行设置以及其中有多少文本。

最新更新