How to change indent on bulleted list on PPT slide using pptx python library

1.4k views Asked by At

I have started using 'pptx' library to programmatically generate some PPT based report. We have a company template which I am using as a base. It contains a master slide with bulleted list in single column format which looks like this (but with different formatting for each level such as bullet type and color. Sorry cannot share actual pic here):

Bulleted list format

I wanted to know if there is a way to change the position of the various levels as we would change from the ruler (or Right Click > Paragraphs > indentation) in MS PowerPoint..? If I change "level" parameter of the bulleted list it changes from first level to second level along with all the formatting.

shape.text_frame.paragraphs[0].level = 2

But I would just like to shift the first level by a few centimetres towards right. So it would look like:

Bulleted list shifted to right

I know one obvious way to achieve is by adding new master slide with required format and using that. But if one needs to change indents multiple times, it would be difficult to add new master slide for each specific case. Thus I am searching if there is a way to do in programmatically using 'pptx' functionality. So far I was unable to find such feature in 'pptx', but I might have missed it may be or there is possibly some workaround. If so I would be interested to know.

1

There are 1 answers

0
scanny On BEST ANSWER

The short answer is "no". The current version of python-pptx does not support bullet formatting in its API.

To do this you would need to manipulate the underlying XML directly. You can search on "python-pptx workaround function" to get some examples.

I believe the element of interest is p:sp/p:txBody/a:lstStyle, containing elements like "lvl1pPr" and "lvl2pPr" and so on.

A reference to the p:txBody element is available on Shape.text_frame._element