Skill 详情
python-pptx
Direct programmatic PowerPoint creation and manipulation skill.
使用前先检查
自动化审核只检查相关性,不代表安全审查或推荐。使用前请阅读来源中的说明。
SKILL.md
这段内容是审核时保存的快照。外部来源才是完整且最新的版本。
---
name: python-pptx
description: Create and manipulate PowerPoint presentations programmatically. Build slide decks with layouts, shapes, charts, tables, and images. Generate data-driven presentations from templates.
version: 1.0.0
category: office-docs
type: skill
capabilities:
- presentation_creation
- slide_layouts
- shape_manipulation
- chart_generation
- table_creation
- image_insertion
- template_based_generation
- master_slide_customization
tools:
- python
- python-pptx
- Pillow
tags: [powerpoint, pptx, presentation, slides, charts, office-automation]
platforms: [windows, macos, linux]
related_skills:
- python-docx
- openpyxl
- plotly
---
# Python-pptx PowerPoint Automation Skill
## Overview
Python-pptx is a Python library for creating and updating PowerPoint (.pptx) presentations. This skill covers comprehensive patterns for presentation automation including:
- **Presentation creation** with multiple slide layouts
- **Shape manipulation** including text boxes, images, and geometric shapes
- **Chart generation** for data visualization within slides
- **Table creation** for structured data display
- **Master slide customization** for branding consistency
- **Template-based generation** for consistent presentations
- **Placeholder management** for dynamic content insertion
## When to Use This Skill
### USE when:
- Generating presentations from data automatically
- Creating standardized report presentations
- Building slide decks with consistent branding
- Automating dashboard presentations
- Creating training materials from templates
- Generating client presentations from databases
- Building presentation pipelines for regular reports
- Creating slides with charts and tables from data
- Mass-producing presentations with variable content
### DON'T USE when:
- Need real-time presentation editing (use PowerPoint)
- Creating presentations with complex animations
- Need advanced transitions (limited support)
- Require embedded videos with playback controls
- Need to preserve complex PowerPoint features
- Creating presentations from scratch without Python (use PowerPoint)
## Prerequisites
### Installation
```bash
# Basic installation
pip install python-pptx
# Using uv (recommended)
uv pip install python-pptx
# With image support
pip install python-pptx Pillow
# Full installation for charts
pip install python-pptx Pillow lxml
```
### Verify Installation
```python
from pptx import Presentation
from pptx.util import Inches, Pt
from pptx.enum.shapes import MSO_SHAPE
from pptx.enum.text import PP_ALIGN
print("python-pptx installed successfully!")
```
## Core Capabilities
### 1. Basic Presentation Creation
```python
"""
Create a basic PowerPoint presentation with common slide types.
"""
from pptx import Presentation
from pptx.util import Inches, Pt
from pptx.enum.text import PP_ALIGN, MSO_ANCHOR
from pptx.dml.color import RgbColor
from pptx.enum.shapes import MSO_SHAPE
def create_basic_presentation(output_path: str) -> None:
"""Create a basic presentation with various slide types."""
# Create presentation
prs = Presentation()
# Set slide dimensions (16:9 widescreen)
prs.slide_width = Inches(13.333)
prs.slide_height = Inches(7.5)
# Slide 1: Title Slide
title_layout = prs.slide_layouts[0] # Title slide layout
slide1 = prs.slides.add_slide(title_layout)
title = slide1.shapes.title
subtitle = slide1.placeholders[1]
title.text = "Q1 2026 Business Review"
subtitle.text = "Strategic Planning and Performance Analysis"
# Format title
for paragraph in title.text_frame.paragraphs:
paragraph.font.size = Pt(44)
paragraph.font.bold = True
# Slide 2: Title and Content
bullet_layout = prs.slide_layouts[1] # Title and content
slide2 = prs.slides.add_slide(bullet_layout)
title2 = slide2.shapes.title
body2 = slide2.placeholders[1]
title2.text = "Key Highlights"
tf = body2.text_frame
tf.在 GitHub 阅读完整来源 (打开外部页面)