Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

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.

like image 949
jayS Avatar asked Oct 26 '25 01:10

jayS


1 Answers

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

like image 106
scanny Avatar answered Oct 28 '25 13:10

scanny



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!