2017-08-14 23 views
3

如何將文本設置爲頂部(標準正文中有第一行格式設置),並且未設置爲TOP對齊方式?Python pptx - 如何設置項目符號點和頂部對齊方式

Add_paragraph函數未激活第一個子彈點級別(級別= 0)?

有人知道如何解決這個問題? (見圖片來了解左邊的問題,並在右側的目標)

# 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

+0

https://python-pptx.readthedocs.io/en/latest/user/quickstart.html#add-textbox-example – Joe

+1

[This](https://github.com/scanny/python-pptx/issues)/100)問題似乎表明,目前還沒有一個選項可以添加要點。 – ikkuh

回答

1

有兩個部分你的問題。第一個很容易 - 如何設置頂部對齊。看起來這些形狀具有默認的「中心」垂直對齊。在給出的代碼中,您正在設置單個段落的垂直錨點。請嘗試將text_frame的垂直定位點設置爲MSO_VERTICAL_ANCHOR.TOP。

text_frame.vertical_anchor = MSO_VERTICAL_ANCHOR.TOP 

對於第二部分,在那裏你需要的子彈,我不認爲PPTX必須開啓/關閉子彈的功能。唯一的方法是在主幻燈片中創建具有所需文本格式的形狀,並將其用作起點。這可以通過編輯模板(幻燈片母版)完成。見例如,您可以創建矩形形狀的文字,如下圖所示: -

Shape with Text formating

希望有所幫助。

相關問題