3

How can I set the text to Top (there is a a first line in standard body formating set upfront) and it is not set to TOP alignment ?

Add_paragraph function did not activate the fist bullet points level (level = 0)?

Someone got an idea on how to solve this issue? (see picture to understand the issue on the left and the goal on the right side)

# Shape position
left = Inches(0.4)
top = Inches(1.5)
width = Inches(4.5)
height = Inches(1.6)

box = shape.add_shape(MSO_SHAPE.RECTANGLE, left, top, width, height)
text_frame = box.text_frame
text_frame.clear()  # not necessary for newly-created shape
#Fill
fill = box.fill
line = box.line
fill.solid()
fill.fore_color.theme_color = MSO_THEME_COLOR.ACCENT_6
line.color.theme_color = MSO_THEME_COLOR.ACCENT_6

p = text_frame.add_paragraph()
run = p.add_run()
# bullet ?
#p.level = 0
# Top position?
p.vertical_anchor = MSO_ANCHOR.TOP
p.alignment = PP_ALIGN.LEFT    
p.margin_left = Inches(0.02)
p.margin_top = Inches(0.00)
#p.margin_bottom = Inches(0.08)

run.text = "..."  
# Fonts
font = run.font
font.name = 'Arial (Body)'
font.size = Pt(8)
font.bold = False
font.italic = None  # cause value to be inherited from theme
font.color.theme_color = MSO_THEME_COLOR.ACCENT_1

enter image description here

otluk
  • 317
  • 1
  • 4
  • 16
  • https://python-pptx.readthedocs.io/en/latest/user/quickstart.html#add-textbox-example – Joe Aug 14 '17 at 06:56
  • 1
    [This](https://github.com/scanny/python-pptx/issues/100) issue from 2014 seems to indicate that there isn't an option yet to add bullet points. – ikkuh Aug 14 '17 at 07:05

1 Answers1

2

There are two parts to your question. First one is easy - how to set Top alignment. It seems the shapes have default 'center' vertical alignment. In the code given in question, you are setting Vertical anchor of individual paragraph. Instead try setting Vertical anchor of the text_frame to MSO_VERTICAL_ANCHOR.TOP.

text_frame.vertical_anchor = MSO_VERTICAL_ANCHOR.TOP

For the second part, where you need bullets, I don't think pptx has the functionality to switch on/off bullets. The only way is to create a shape with required text formatting in a master slide and use that as starting point. This can be done by editing the template (Slide Master). See for example, you can create rectangular text shape as shown below:-

Shape with Text formating

Hope that helps.

Community
  • 1
  • 1
jayS
  • 168
  • 8