簡體   English   中英

Python-pptx 繪制一條垂直線

[英]Python-pptx drawing a vertical line

我正在嘗試使用 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')

使用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)
)

前兩個長度值指定起點,其余兩個指定終點。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM