Standardmäßig ist der Prompt ausgewählt, der zuerst die Quelle prüft. Sie können zu einem direkten Befehl wechseln oder eine lokale Kopie herunterladen.
Quelldateien prüfen
Lesen Sie SKILL.md und alle von SkillsMP angezeigten Begleitdateien, bevor Sie sich für eine Installation entscheiden.
Mit Codex oder Claude installieren Kopieren Sie diesen Prompt, fügen Sie ihn in Codex, Claude oder einen anderen Assistant ein und lassen Sie die Skill-Seite prüfen und installieren.
Ein direkter Befehl überspringt den Prüf-Prompt. Prüfen Sie die Quelle, bevor Sie ihn ausführen.
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
# 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
from pptx import Presentation
from pptx.util import Inches, Pt
from pptx.enum.shapes import MSO_SHAPE
pptx.enum.text PP_ALIGN
()
"""
Generate presentations from templates with placeholder replacement.
"""from pptx import Presentation
from pptx.util import Inches, Pt
from pptx.enum.shapes import MSO_SHAPE_TYPE
from typing importDict, Any, Listfrom pathlib import Path
from copy import deepcopy
defreplace_text_in_shapes(slide, replacements: Dict[str, str]) -> None:
"""Replace placeholder text in all shapes on a slide."""for shape in slide.shapes:
if shape.has_text_frame:
for paragraph in shape.text_frame.paragraphs:
for run in paragraph.runs:
for key, value in replacements.items():
iff'{{{{{key}}}}}'in run.text:
run.text = run.text.replace(f'{{{{{key}}}}}', str(value))
if shape.has_table:
for row in shape.table.rows:
for cell in row.cells:
for paragraph in cell.text_frame.paragraphs:
for run in paragraph.runs:
for key, value in replacements.items():
iff'{{{{{key}}}}}'in run.text:
run.text = run.text.replace(
f'{{{{{key}}}}}',
str(value)
)
defgenerate_from_template(
template_path: str,
output_path: str,
data: Dict[str, Any]
) -> None:
"""Generate presentation from template with data substitution."""
prs = Presentation(template_path)
for slide in prs.slides:
replace_text_in_shapes(slide, data)
prs.save(output_path)
print(f"Generated presentation: {output_path}")
defcreate_monthly_report_template(output_path: str) -> None:
"""Create a template for monthly reports."""
prs = Presentation()
# Title slide with placeholders
slide = prs.slides.add_slide(prs.slide_layouts[6])
# Title placeholder
title = slide.shapes.add_textbox(
Inches(0.5), Inches(2.5),
Inches(12), Inches(1.5)
)
tf = title.text_frame
p = tf.paragraphs[0]
p.text = "{{report_title}}"
p.font.size = Pt(44)
p.font.bold = True
p.alignment = 1# Center# Subtitle
subtitle = slide.shapes.add_textbox(
Inches(0.5), Inches(4),
Inches(12), Inches(1)
)
tf = subtitle.text_frame
p = tf.paragraphs[0]
p.text = "{{report_period}}"
p.font.size = Pt(24)
p.alignment = 1# Summary slide
slide = prs.slides.add_slide(prs.slide_layouts[6])
title = slide.shapes.add_textbox(
Inches(0.5), Inches(0.5),
Inches(12), Inches(1)
)
tf = title.text_frame
p = tf.paragraphs[0]
p.text = "Executive Summary"
p.font.size = Pt(32)
p.font.bold = True# Key metrics boxes
metrics = [
("Revenue", "{{revenue}}"),
("Customers", "{{customers}}"),
("Growth", "{{growth}}"),
]
for i, (label, placeholder) inenumerate(metrics):
x = 1 + (i * 4)
# Label
label_box = slide.shapes.add_textbox(
Inches(x), Inches(2),
Inches(3), Inches(0.5)
)
tf = label_box.text_frame
p = tf.paragraphs[0]
p.text = label
p.font.size = Pt(14)
p.alignment = 1# Value box
shape = slide.shapes.add_shape(
MSO_SHAPE.ROUNDED_RECTANGLE,
Inches(x), Inches(2.5),
Inches(3), Inches(1.5)
)
shape.fill.solid()
shape.fill.fore_color.rgb = RgbColor(0x44, 0x72, 0xC4)
tf = shape.text_frame
p = tf.paragraphs[0]
p.text = placeholder
p.font.size = Pt(28)
p.font.bold = True
p.font.color.rgb = RgbColor(255, 255, 255)
p.alignment = 1
prs.save(output_path)
print(f"Template saved: {output_path}")
defbatch_generate_presentations(
template_path: str,
data_list: List[Dict[str, Any]],
output_dir: str) -> List[str]:
"""Generate multiple presentations from template."""
output_path = Path(output_dir)
output_path.mkdir(parents=True, exist_ok=True)
generated = []
for data in data_list:
filename = f"{data.get('filename', 'presentation')}.pptx"
file_path = output_path / filename
generate_from_template(template_path, str(file_path), data)
generated.append(str(file_path))
return generated
# Example usage:# create_monthly_report_template('monthly_template.pptx')## data = {# 'report_title': 'Monthly Performance Report',# 'report_period': 'January 2026',# 'revenue': '$12.5M',# 'customers': '45,000',# 'growth': '+15%'# }# generate_from_template('monthly_template.pptx', 'january_report.pptx', data)
Integration Examples
Data-Driven Presentation from Database
"""
Generate presentations from database queries.
"""from pptx import Presentation
from pptx.util import Inches, Pt
from pptx.chart.data import CategoryChartData
from pptx.enum.chart import XL_CHART_TYPE
import sqlite3
from datetime import datetime
defgenerate_database_presentation(
db_path: str,
output_path: str) -> None:
"""Generate presentation from database data."""
conn = sqlite3.connect(db_path)
prs = Presentation()
# Title slide
slide = prs.slides.add_slide(prs.slide_layouts[0])
slide.shapes.title.text = "Sales Analysis Report"
slide.placeholders[1].text = f"Generated: {datetime.now().strftime('%Y-%m-%d')}"# Query 1: Sales by region
cursor = conn.execute("""
SELECT region, SUM(amount) as total
FROM sales
GROUP BY region
ORDER BY total DESC
""")
regions = cursor.fetchall()
# Create chart slide
slide = prs.slides.add_slide(prs.slide_layouts[5])
slide.shapes.title.text = "Sales by Region"
chart_data = CategoryChartData()
chart_data.categories = [r[0] for r in regions]
chart_data.add_series('Sales', [r[1] for r in regions])
slide.shapes.add_chart(
XL_CHART_TYPE.BAR_CLUSTERED,
Inches(1), Inches(1.5), Inches(11), Inches(5.5),
chart_data
)
# Query 2: Monthly trend
cursor = conn.execute("""
SELECT strftime('%Y-%m', date) as month, SUM(amount)
FROM sales
GROUP BY month
ORDER BY month
""")
monthly = cursor.fetchall()
slide = prs.slides.add_slide(prs.slide_layouts[5])
slide.shapes.title.text = "Monthly Sales Trend"
chart_data = CategoryChartData()
chart_data.categories = [m[0] for m in monthly]
chart_data.add_series('Sales', [m[1] for m in monthly])
slide.shapes.add_chart(
XL_CHART_TYPE.LINE_MARKERS,
Inches(1), Inches(1.5), Inches(11), Inches(5.5),
chart_data
)
conn.close()
prs.save(output_path)
print(f"Database presentation saved: {output_path}")
Pandas DataFrame to Presentation
"""
Generate presentations from pandas DataFrames.
"""import pandas as pd
from pptx import Presentation
from pptx.util import Inches, Pt
from pptx.dml.color import RgbColor
from pptx.enum.text import PP_ALIGN, MSO_ANCHOR
defdataframe_to_slide(
prs: Presentation,
df: pd.DataFrame,
title: str,
max_rows: int = 15) -> None:
"""Add DataFrame as table to presentation."""
slide = prs.slides.add_slide(prs.slide_layouts[5])
slide.shapes.title.text = title
# Limit rows if necessary
display_df = df.head(max_rows)
rows, cols = display_df.shape
rows += 1# For header# Calculate dimensions
table_width = min(cols * 1.5, 12)
left = Inches((13.333 - table_width) / 2)
table = slide.shapes.add_table(
rows, cols,
left, Inches(1.5),
Inches(table_width), Inches(0.4 * rows)
).table
# Headersfor i, col_name inenumerate(display_df.columns):
cell = table.cell(0, i)
cell.text = str(col_name)
cell.fill.solid()
cell.fill.fore_color.rgb = RgbColor(0x2F, 0x54, 0x96)
para = cell.text_frame.paragraphs[0]
para.font.bold = True
para.font.color.rgb = RgbColor(255, 255, 255)
para.font.size = Pt(10)
para.alignment = PP_ALIGN.CENTER
# Datafor row_idx, (_, row) inenumerate(display_df.iterrows(), start=1):
for col_idx, value inenumerate(row):
cell = table.cell(row_idx, col_idx)
cell.text = str(value)
para = cell.text_frame.paragraphs[0]
para.font.size = Pt(9)
para.alignment = PP_ALIGN.CENTER
defcreate_dataframe_presentation(
dataframes: dict,
output_path: str) -> None:
"""Create presentation from multiple DataFrames."""
prs = Presentation()
# Title slide
slide = prs.slides.add_slide(prs.slide_layouts[0])
slide.shapes.title.text = "Data Analysis Report"for title, df in dataframes.items():
dataframe_to_slide(prs, df, title)
prs.save(output_path)
print(f"DataFrame presentation saved: {output_path}")
Best Practices
1. Template Design
"""Best practices for template-based generation."""# DO: Use consistent placeholder naming
PLACEHOLDERS = {
'title': '{{title}}',
'subtitle': '{{subtitle}}',
'date': '{{date}}',
'author': '{{author}}'
}
# DO: Create reusable slide buildersclassSlideBuilder:
def__init__(self, prs):
self.prs = prs
defadd_title_slide(self, title, subtitle):
slide = self.prs.slides.add_slide(self.prs.slide_layouts[0])
slide.shapes.title.text = title
if subtitle:
slide.placeholders[1].text = subtitle
return slide
defadd_content_slide(self, title, bullets):
slide = self.prs.slides.add_slide(self.prs.slide_layouts[1])
slide.shapes.title.text = title
tf = slide.placeholders[1].text_frame
tf.text = bullets[0]
for bullet in bullets[1:]:
p = tf.add_paragraph()
p.text = bullet
return slide
2. Performance Optimization
"""Performance tips for large presentations."""# DO: Reuse color objects
COLORS = {
'primary': RgbColor(0x2F, 0x54, 0x96),
'secondary': RgbColor(0x70, 0xAD, 0x47),
'accent': RgbColor(0xED, 0x7D, 0x31)
}
# DO: Batch similar operationsdefadd_multiple_charts(prs, chart_data_list):
for title, data, chart_type in chart_data_list:
slide = prs.slides.add_slide(prs.slide_layouts[5])
slide.shapes.title.text = title
# Add chart...
# Problem: Slide layout index out of range# Solution: Check available layouts
prs = Presentation()
for i, layout inenumerate(prs.slide_layouts):
print(f"{i}: {layout.name}")
# Common layouts:# 0: Title Slide# 1: Title and Content# 5: Title Only# 6: Blank
2. Text Overflow
# Problem: Text doesn't fit in shape# Solution: Adjust font size or enable auto-fit
tf = shape.text_frame
tf.auto_size = True# Enable auto-sizing# Or manually adjust
tf.paragraphs[0].font.size = Pt(10)
3. Chart Not Displaying
# Problem: Chart appears empty# Solution: Verify data structure# DO: Ensure categories and series match
chart_data = CategoryChartData()
chart_data.categories = ['A', 'B', 'C'] # Must have values
chart_data.add_series('Series 1', (1, 2, 3)) # Same length