[python] python-pptx 테두리(border) 두께 설정하기

python-pptx는 파이썬으로 PowerPoint 파일을 만들고 편집하는 데 사용되는 라이브러리입니다. 이 라이브러리를 사용하여 슬라이드에 있는 모양들의 테두리 두께를 설정하는 방법에 대해 알아보겠습니다.

필요한 패키지 설치하기

먼저, python-pptx를 설치해야 합니다. 다음 명령을 사용하여 설치할 수 있습니다:

$ pip install python-pptx

테두리 설정하기

from pptx import Presentation
from pptx.enum.shapes import MSO_SHAPE
from pptx.enum.dml import MSO_LINE

# PowerPoint 파일을 로드합니다.
presentation = Presentation("sample.pptx")

# 슬라이드의 모든 모양들을 순회합니다.
for slide in presentation.slides:
    for shape in slide.shapes:
        fill = shape.fill
        if shape.shape_type == MSO_SHAPE.RECTANGLE and fill.background is not None:
            # 테두리 두께를 2.5로 설정합니다.
            line = shape.line
            line.width = 2.5
            line.dash_style = MSO_LINE.SOLID

# 수정한 파일을 저장합니다.
presentation.save("modified.pptx")

위의 예제 코드는 입력으로 주어진 PowerPoint 파일(sample.pptx)을 열고, 각 슬라이드의 사각형 모양들의 테두리 두께를 2.5로 설정합니다. 수정한 파일은 modified.pptx로 저장됩니다.

결론

위의 예제 코드를 사용하면 python-pptx를 통해 PowerPoint 파일에서 테두리 두께를 설정할 수 있습니다. 이를 활용하여 다양한 슬라이드 편집 작업을 수행할 수 있습니다.

참고 문서: