pptx-manipulation은(는) 무엇을 하나요?
참고: 이 스킬은 Python-pptx 라이브러리를 사용하여 PowerPoint 프레젠테이션을 생성하고 수정합니다.
개요
이 스킬은 PowerPoint 프레젠테이션 파일(.pptx)을 프로그래밍 방식으로 조작할 수 있는 기능을 제공합니다. 주요 작업:
- 프레젠테이션 생성 및 열기
- 슬라이드 추가, 복제, 삭제
- 텍스트 상자, 도형, 이미지, 표, 차트 추가 및 편집
- 슬라이드 마스터 및 레이아웃 수정
- 슬라이드 노트 추가
- 프레젠테이션 저장
전제 조건
python-pptx라이브러리 설치 필요:pip install python-pptx
사용 예제
기본 사용법
from pptx import Presentation
from pptx.util import Inches
# 새 프레젠테이션 생성
prs = Presentation()
# 제목 슬라이드 추가
slide_layout = prs.slide_layouts[0]
slide = prs.slides.add_slide(slide_layout)
# 제목 설정
title = slide.shapes.title
title.text = "안녕하세요, PowerPoint!"
# 부제목 설정
subtitle = slide.placeholders[1]
subtitle.text = "Python-pptx로 생성됨"
# 저장
prs.save('test.pptx')
기존 프레젠테이션 열기
prs = Presentation('existing.pptx')
주요 함수 및 메서드
| 함수/메서드 | 설명 |
|---|---|
Presentation() | 빈 프레젠테이션 생성 |
Presentation(file) | 기존 파일 열기 |
prs.slides.add_slide(layout) | 새 슬라이드 추가 |
slide.shapes.title | 슬라이드 제목 접근 |
slide.placeholders[idx] | 특정 플레이스홀더 접근 |
prs.save(path) | 파일 저장 |
고급 기능
이미지 삽입
from pptx.util import Inches
# 이미지 추가 (왼쪽 상단 (1인치, 1인치) 위치, 너비 4인치)
slide.shapes.add_picture('image.png', Inches(1), Inches(1), width=Inches(4))
표 생성
from pptx.util import Inches
table = slide.shapes.add_table(rows=3, cols=3, left=Inches(1), top=Inches(2), width=Inches(6), height=Inches(2))
table.table.cell(0, 0).text = "헤더 1"
table.table.cell(0, 1).text = "헤더 2"
table.table.cell(0, 2).text = "헤더 3"
슬라이드 마스터 수정
# 마스터 슬라이드 접근
master = prs.slide_masters[0]
# 레이아웃 목록
for layout in master.slide_layouts:
print(layout.name)
참고 사항
- Python-pptx는 모든 PowerPoint 기능을 완벽하게 지원하지는 않습니다.
- 복잡한 애니메이션이나 전환 효과는 지원되지 않을 수 있습니다.
- 파일 경로는 로컬 시스템의 절대 또는 상대 경로여야 합니다.