// "Professional PowerPoint presentation creation, editing, and automation with support for layouts, templates, charts, images, and formatting. Use when working with .pptx files for: (1) Creating presentations from scratch, (2) Editing existing presentations, (3) Applying templates and themes, (4) Adding charts and visualizations, (5) Bulk slide generation, (6) Presentation automation"
| name | pptx |
| description | Professional PowerPoint presentation creation, editing, and automation with support for layouts, templates, charts, images, and formatting. Use when working with .pptx files for: (1) Creating presentations from scratch, (2) Editing existing presentations, (3) Applying templates and themes, (4) Adding charts and visualizations, (5) Bulk slide generation, (6) Presentation automation |
This skill provides comprehensive PowerPoint presentation creation, editing, and automation capabilities using Python's python-pptx library. Create professional presentations programmatically with full control over layouts, themes, content, charts, and visualizations.
Install the required library:
pip install python-pptx
# or with uv
uv pip install python-pptx
Basic imports:
from pptx import Presentation
from pptx.util import Inches, Pt, Cm
from pptx.dml.color import RGBColor
from pptx.enum.text import PP_ALIGN, MSO_ANCHOR
from pptx.chart.data import CategoryChartData
from pptx.enum.chart import XL_CHART_TYPE
For complete library setup and supporting packages (Pillow, pandas, matplotlib), see references/library-setup.md.
Goal: Create a professional presentation with title slide, content slides, and conclusion.
Steps:
Initialize Presentation
Add Title Slide
prs.slide_layouts[0])Add Content Slides
Add Visual Elements
Save Presentation
Quick Example:
from pptx import Presentation
from pptx.util import Inches, Pt
prs = Presentation()
prs.slide_width = Inches(10)
prs.slide_height = Inches(7.5)
# Title slide
slide = prs.slides.add_slide(prs.slide_layouts[0])
slide.shapes.title.text = "Q4 Business Review"
slide.placeholders[1].text = "Prepared by: Jane Doe\nDate: October 25, 2025"
prs.save('presentation.pptx')
See examples/business-presentation.md for complete implementation.
Goal: Create data visualizations with bar, line, and pie charts.
Steps:
CategoryChartDataQuick Example:
from pptx.chart.data import CategoryChartData
from pptx.enum.chart import XL_CHART_TYPE
chart_data = CategoryChartData()
chart_data.categories = ['Q1', 'Q2', 'Q3', 'Q4']
chart_data.add_series('2025', (9.5, 10.8, 11.2, 13.1))
chart = slide.shapes.add_chart(
XL_CHART_TYPE.COLUMN_CLUSTERED,
Inches(1), Inches(2), Inches(8), Inches(4.5),
chart_data
).chart
See examples/chart-examples.md for all chart types.
Goal: Add, position, and format images in presentations.
Steps:
slide.shapes.add_picture()Quick Example:
# Add image with auto-scaled aspect ratio
pic = slide.shapes.add_picture('logo.png', Inches(1), Inches(1), height=Inches(2))
# Center image on slide
pic.left = int((prs.slide_width - pic.width) / 2)
pic.top = int((prs.slide_height - pic.height) / 2)
See examples/image-handling.md for advanced techniques.
Goal: Add structured data tables with formatting.
Steps:
Quick Example:
table = slide.shapes.add_table(4, 3, Inches(1.5), Inches(2), Inches(7), Inches(3)).table
# Header formatting
cell = table.cell(0, 0)
cell.text = "Product"
cell.text_frame.paragraphs[0].font.bold = True
cell.fill.solid()
cell.fill.fore_color.rgb = RGBColor(0, 51, 102)
See examples/table-examples.md for advanced formatting.
Goal: Modify existing PowerPoint files.
Steps:
Presentation('file.pptx')Quick Example:
prs = Presentation('existing.pptx')
# Find and update text
for slide in prs.slides:
for shape in slide.shapes:
if hasattr(shape, "text") and "Old Name" in shape.text:
shape.text = shape.text.replace("Old Name", "New Name")
prs.save('updated.pptx')
See examples/editing-presentations.md for slide copying and advanced editing.
Goal: Apply consistent branding with master slides and templates.
Steps:
Presentation('template.pptx')Quick Example:
prs = Presentation('corporate_template.pptx')
# Use template layouts
title_slide = prs.slides.add_slide(prs.slide_layouts[0])
content_slide = prs.slides.add_slide(prs.slide_layouts[1])
# Layouts inherit master formatting
prs.save('branded_presentation.pptx')
See references/templates-and-themes.md for master slide customization.
Goal: Generate multiple slides automatically from data.
Steps:
Quick Example:
import pandas as pd
df = pd.read_csv('employee_data.csv')
prs = Presentation()
for _, row in df.iterrows():
slide = prs.slides.add_slide(prs.slide_layouts[1])
slide.shapes.title.text = row['Name']
# Add employee details to slide body
prs.save('employee_directory.pptx')
See examples/bulk-generation.md for complete implementations.
For complete design guidelines, see references/design-best-practices.md.
BRAND_COLORS = {
'primary': RGBColor(0, 51, 102),
'secondary': RGBColor(0, 153, 204),
'accent': RGBColor(255, 102, 0)
}
# Apply to text
shape.text_frame.paragraphs[0].font.color.rgb = BRAND_COLORS['primary']
# Apply to fill
shape.fill.solid()
shape.fill.fore_color.rgb = BRAND_COLORS['secondary']
def center_shape(shape, prs):
"""Center shape on slide."""
shape.left = int((prs.slide_width - shape.width) / 2)
shape.top = int((prs.slide_height - shape.height) / 2)
from pptx.enum.text import MSO_AUTO_SIZE
text_frame = shape.text_frame
text_frame.auto_size = MSO_AUTO_SIZE.TEXT_TO_FIT_SHAPE # Shrink text
# or
text_frame.auto_size = MSO_AUTO_SIZE.SHAPE_TO_FIT_TEXT # Expand shape
"ModuleNotFoundError: No module named 'pptx'"
pip install python-pptx
"AttributeError: 'NoneType' object has no attribute..."
[p.placeholder_format.idx for p in slide.placeholders]Images not found
os.path.abspath('image.png')os.path.exists(img_path)Text doesn't fit
text_frame.auto_size = MSO_AUTO_SIZE.TEXT_TO_FIT_SHAPEFile size too large
For complete troubleshooting, see references/troubleshooting.md.
The scripts/pptx_helper.py module provides utility functions:
create_presentation(): Initialize with defaultsadd_title_slide(): Add formatted title slideadd_bullet_slide(): Add slide with bullet pointsadd_image_slide(): Add slide with centered imageadd_chart_slide(): Add slide with chartadd_table_slide(): Add formatted tableapply_brand_colors(): Apply consistent color schemeoptimize_images(): Batch optimize imagesUsage:
from scripts.pptx_helper import create_presentation, add_title_slide, add_chart_slide
prs = create_presentation(title="My Presentation")
add_title_slide(prs, "Main Title", "Subtitle")
add_chart_slide(prs, "Sales Data", chart_type='bar',
categories=['Q1', 'Q2', 'Q3', 'Q4'],
values=[10, 20, 15, 25])
prs.save('output.pptx')
When to Use This Skill: