Python pptx - 如何设置项目符号点和顶部对齐
Python pptx - How to set bullet points and top alignment
如何将文本设置为顶部(标准正文格式中有第一行预先设置)而不设置为顶部对齐?
Add_paragraph功能没有激活拳头弹点等级(level=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
您的问题分为两部分。第一个很简单 - 如何设置顶部对齐。这些形状似乎具有默认的 'center' 垂直对齐方式。在有问题的代码中,您正在设置单个段落的垂直锚点。而是尝试将 text_frame 的垂直锚点设置为 MSO_VERTICAL_ANCHOR.TOP。
text_frame.vertical_anchor = MSO_VERTICAL_ANCHOR.TOP
第二部分,需要子弹的地方,我觉得pptx没有切换on/off子弹的功能。唯一的方法是在母版幻灯片中创建具有所需文本格式的形状,并将其用作起点。这可以通过编辑模板(幻灯片母版)来完成。例如,您可以创建矩形文本形状,如下所示:-
Shape with Text formating
希望对您有所帮助。
如何将文本设置为顶部(标准正文格式中有第一行预先设置)而不设置为顶部对齐?
Add_paragraph功能没有激活拳头弹点等级(level=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
您的问题分为两部分。第一个很简单 - 如何设置顶部对齐。这些形状似乎具有默认的 'center' 垂直对齐方式。在有问题的代码中,您正在设置单个段落的垂直锚点。而是尝试将 text_frame 的垂直锚点设置为 MSO_VERTICAL_ANCHOR.TOP。
text_frame.vertical_anchor = MSO_VERTICAL_ANCHOR.TOP
第二部分,需要子弹的地方,我觉得pptx没有切换on/off子弹的功能。唯一的方法是在母版幻灯片中创建具有所需文本格式的形状,并将其用作起点。这可以通过编辑模板(幻灯片母版)来完成。例如,您可以创建矩形文本形状,如下所示:-
Shape with Text formating
希望对您有所帮助。