scanny / python-pptx

Create Open XML PowerPoint documents in Python
MIT License
2.42k stars 524 forks source link

feature: add line endings using LineFormat #375

Open yuratak opened 6 years ago

yuratak commented 6 years ago

I'd like to add a left and/or right arrow connector. In Line/Connector Shape API, there is no arrow type MsoConnector.

Name Value Description
msoConnectorCurve 3 Curved connector.
msoConnectorElbow 2 Elbow connector.
msoConnectorStraight 1 Straight line connector.
msoConnectorTypeMixed -2 Return value only; indicates a combination of the other states.

But in Specimen XML, I see that it's possible to add an arrow connector.

<p:cxnSp>
  <p:nvCxnSpPr>
    <p:cNvPr id="7" name="Straight Arrow Connector 6"/>
    <p:cNvCxnSpPr/>
    <p:nvPr/>
  </p:nvCxnSpPr>
  <p:spPr>
    <a:xfrm>
      <a:off x="950964" y="1673307"/>
      <a:ext cx="1257921" cy="0"/>
    </a:xfrm>
    <a:prstGeom prst="straightConnector1">
      <a:avLst/>
    </a:prstGeom>
    <a:ln>
      <a:tailEnd type="arrow"/>
    </a:ln>
  </p:spPr>
  <p:style>
    <a:lnRef idx="2">
      <a:schemeClr val="accent1"/>
    </a:lnRef>
    <a:fillRef idx="0">
      <a:schemeClr val="accent1"/>
    </a:fillRef>
    <a:effectRef idx="1">
      <a:schemeClr val="accent1"/>
    </a:effectRef>
    <a:fontRef idx="minor">
      <a:schemeClr val="tx1"/>
    </a:fontRef>
  </p:style>
</p:cxnSp>

How can I do this ? Thank you.

scanny commented 6 years ago

Although it appears as a separate option in the PowerPoint UI, a connector with arrowheads is not a separate shape type. The line of any shape can have arrowheads.

Line endings such as arrowheads have not been added to the API yet however.

MutedPermit commented 5 years ago

Are there any progress on this feature request? I would be very interested in!

khouryrami commented 4 years ago

Any progress on this yet? - if not, is there a way to hack the xml through python pptx to get it done? This is urgent. Thanks!

y-solopov commented 4 years ago

Any progress on this yet? - if not, is there a way to hack the xml through python pptx to get it done? This is urgent. Thanks!

from pptx.oxml import parse_xml
line_elem=connector.line._get_or_add_ln()
line_elem.append(parse_xml("""
        <a:tailEnd type="arrow" xmlns:a="http://schemas.openxmlformats.org/drawingml/2006/main"/>
 """))