RPA/Python

[python-pptx] 도형 객체 삽입

꼰대 2021. 5. 8. 16:10

from pptx import Presentation

from pptx.util import Inches

from pptx.enum.shapes import MSO_SHAPE    # MSO_SHAPE_TYPE의 Alias

from pptx.enum.dml import MSO_THEME_COLOR # MSO_THEME_COLOR_INDEX의 Alias



prs = Presentation()

slide_layout = prs.slide_layouts[6]

slide = prs.slides.add_slide(slide_layout)

 

# 첫번째 도형 위치 및 크기

left = top = height = width = Inches(1)

 

# 첫번째 모서리가 둥근 사각형 도형 생성

# 도형값 : https://python-pptx.readthedocs.io/en/latest/api/enum/MsoAutoShapeType.html?highlight=MSO_SHAPE#mso-auto-shape-type

ad_shape = slide.shapes.add_shape(MSO_SHAPE.ROUNDED_RECTANGLE, left, top, width, height)

 

# 두번째 도형 위치 및 크기

left = Inches(5)

top = height = width = Inches(1)

 

# 두번쨰 아래쪽 화살표 도형 생성

ad_shape = slide.shapes.add_shape(MSO_SHAPE.DOWN_ARROW, left, top, width, height)

 

# 도형 색 채우기

# 색값 : https://python-pptx.readthedocs.io/en/latest/api/enum/MsoThemeColorIndex.html?highlight=MSO_THEME_COLOR#mso-theme-color-index

arrow = ad_shape.fill

arrow.solid()

arrow.fore_color.theme_color = MSO_THEME_COLOR.ACCENT_2

 

# 도형 회전 (+ 시계방향, - 시계반대방향)

ad_shape.rotation = -30



prs.save('demo.pptx')

반응형