0

I have a powerpoint slide with a table. In the final column I have created a bulleted item which I'd like to copy to fit an arbitrary list of text.

How can I copy the first paragraph (with the bullet) to additional paragraphs. Copying the paragraph element doesn't work and lxml doesnt accept the bullet as a stand alone element.

Relevant code snippet below:

tf6 = tablegf.cell(1, 2).text_frame

comments = [loremipsum.get_sentences(5)]

bullet = '<a:rPr/>'

def addComments(comments, textframe):
    comment = comments[0]
    bulletp = textframe.paragraphs[0]
    bulletp.text = comment
    for comment in comments[1:]:
        p = textframe.add_paragraph()
        p._element = copy.deepcopy(bulletp._element)
        p.text = comment
    for paragraph in textframe.paragraphs:
        paragraph.font.size = Pt(10)
    return


addComments(comments, tf6)

The difference in the XML between a sample bulleted and unbulleted segment shown below. I can't figure out how to add the additional xml to the additional paragraphs

With Bullet

<a:p>
  <a:pPr>
    <a:defRPr sz="1000"/>
  </a:pPr>
  <a:r>
    <a:rPr/>
    <a:t>Massa metus magna urna a orci id nunc proin mattis semper natoque potenti nulla.</a:t>
  </a:r>
</a:p>

Without Bullet

<a:p>
  <a:pPr>
    <a:defRPr sz="1000"/>
  </a:pPr>
  <a:r>
    <a:t>Dolor donec sociis parturient purus erat dui nam.</a:t>
  </a:r>
</a:p>
scanny
  • 26,423
  • 5
  • 54
  • 80
Tahnoon Pasha
  • 5,848
  • 14
  • 49
  • 75
  • 1
    Can you clean up your XML? What are all those `\n`s doing in there? I'm sure that's not actually in the XML. I think you're going to need to go upward a bit, at least to the table cell (``) and see if there is a list or bullet specifying element. I'm not seeing offhand how an `a:rPr` with no attributes or children is going to change the bullet status. – scanny Jan 07 '18 at 21:18
  • thanks @scanny and for the brilliant library. I pasted the output of the `p._element.xml` - the have edited out the \n. I'll check the `` though as the first paragraph is bulleted and the rest aren't it might be at a lower level. Once I've found it - could you point me to the documentation that shows how to edit the xml for subsequent paragraphs please? much obliged. – Tahnoon Pasha Jan 08 '18 at 12:53
  • Your XML starts too late. Bullets are *used* at the Paragraph level, and *defined* entirely somewhere else. If this is similar enough to how bullet lists work in Word/XML, you can look at https://stackoverflow.com/q/36909840/2564301 for inspiration. – Jongware Jan 08 '18 at 23:52

0 Answers0