Python-pptx画一条垂直线

时间:2019-09-11 18:12:08

标签: python-pptx

我正在尝试使用python-pptx模块画一条垂直线,但是还没有。

下面的内容可以帮助我画一条水平线,但是我不确定如何在幻灯片中获得一条垂直线

from pptx import Presentation
from pptx.util import Inches, Pt
from pptx.enum.shapes import MSO_SHAPE


prs = Presentation()
slide = prs.slides.add_slide(prs.slide_layouts[1])
line1 = slide.shapes.add_shape(MSO_SHAPE.LINE_INVERSE, Inches(6), Inches(6), Inches(1), Inches(2))
prs.save('sample.pptx')

1 个答案:

答案 0 :(得分:0)

使用shapes.add_connector()
https://python-pptx.readthedocs.io/en/latest/api/shapes.html#pptx.shapes.shapetree.SlideShapes.add_connector

它的签名是:

add_connector(connector_type, begin_x, begin_y, end_x, end_y)

它的用法如下:

from pptx.enum.shapes import MSO_CONNECTOR
from pptx.util import Cm

line = slide.shapes.add_connector(
    MSO_CONNECTOR.STRAIGHT, Cm(2), Cm(2), Cm(10), Cm(10)
)

前两个长度值指定起点,后两个长度值指定终点。

相关问题