← 返回
未分类

create-pptx

Create PowerPoint presentations (PPTX) using Python and python-pptx. Handles timelines, charts, diagrams, slide layouts, custom colors, shapes, connectors, t...
使用 Python 和 python-pptx 创建 PowerPoint 演示文稿(PPTX),支持时间轴、图表、图示、幻灯片布局、自定义颜色、形状、连接线等功能。
scottliu007 scottliu007 来源
未分类 clawhub v1.0.0 1 版本 99935.9 Key: 无需
★ 0
Stars
📥 1,560
下载
💾 123
安装
1
版本
#latest

概述

Create PowerPoint (python-pptx)

Setup

pip install python-pptx   # or: uv pip install python-pptx

Output scripts to a logical location (e.g., 前端开发/demo/ or project folder),

then run with python3 and open the result.

Core helpers

Read and import scripts/pptx_helpers.py for ready-made drawing primitives:

background, horizontal/vertical lines, textboxes, ovals, diagonal connectors,

and fade transitions. Copy or import as needed.

Key units: EMU (English Metric Units). 1 pt = 12700 EMU, 1 cm ≈ 360000 EMU.

Standard 16:9 slide = 12192000 × 6858000 EMU.

Workflow

  1. Understand the content — milestones, categories, colors, # slides
  2. Plan layout — compute X/Y positions in EMU up front; avoid magic numbers
  3. Build shapes — use helpers or slide.shapes.add_shape/add_textbox
  4. Add transitions — always call add_fade_transition(slide) from helpers
  5. Run and openpython3 script.py && open output.pptx

Multi-slide instead of click animations (WPS-safe default)

WPS does not reliably support click-triggered PowerPoint animations.

Always use multiple slides to reveal content progressively:

Slide 1 → skeleton / structure only
Slide 2 → skeleton + first data layer
Slide 3 → skeleton + all data layers

Add a fade transition (add_fade_transition) to each slide for smooth switching.

If the user explicitly asks for animations AND they are using Microsoft PowerPoint

(not WPS), you may attempt XML-based animations — but read references/wps-compat.md

first for the XML structure and known pitfalls.

Common patterns

Colors & theme

Define all colors as RGBColor constants at the top. Dark backgrounds look

premium — use near-black (0x06, 0x0D, 0x1E) with bright accents.

Timeline layout

TL_L, TL_R = 850000, 11950000        # left/right margins (EMU)
TL_W  = TL_R - TL_L
M_STEP = TL_W // 11                   # 12 months → 11 intervals

def month_x(m):                       # 1-based month → EMU x-position
    return TL_L + M_STEP * (m - 1)

Collision resolution

When multiple cards share the same or nearby X position, spread them:

def resolve_collisions(events, card_w, gap):
    events.sort(key=lambda e: e['cx'])
    need = card_w + gap
    for _ in range(120):
        moved = False
        for i in range(len(events) - 1):
            a, b = events[i], events[i+1]
            if b['cx'] - a['cx'] < need:
                push = (need - (b['cx'] - a['cx'])) / 2
                a['cx'] -= push; b['cx'] += push; moved = True
        if not moved:
            break

Shape IDs for animation

python-pptx assigns shape IDs automatically. To retrieve them after creation:

shp = slide.shapes.add_shape(...)
shape_id = shp.shape_id        # use this in animation XML

For connectors added via raw XML, read back the max existing ID first:

def _max_existing_id(slide):
    return max((int(el.get('id')) for el in slide.element.iter()
                if el.get('id') and el.get('id').isdigit()), default=1)

Template assets

Ready-to-use .pptx base files in assets/. Use them as the starting

Presentation() object to inherit their design/theme:

from pptx import Presentation
prs = Presentation('/Users/scott/.cursor/skills/create-pptx/assets/business-dark.pptx')
FileStyleSource
---------------------
assets/business-dark.pptx深色商务 · Pitch Deck 风格 · 60 slidesSlidesgo "Product Vision Pitch Deck" (Attribution required)
assets/education.pptx明亮教育 · 笔记本课程风格 · 多 slidesSlidesgo "Notebook Lesson XL" (Attribution required)

> Attribution: Free Slidesgo templates require keeping the attribution slide.

> When using these files, do NOT delete the last "Credits" slide.

Reference files

Read the relevant file based on the task:

  • references/pptx-patterns.md — EMU 单位速查、预设形状 ID、连接器 XML、

过渡 XML、多段落文字框、典型脚本结构

  • references/charts.md — python-pptx 原生图表 API:柱状、折线、饼图、散点、

多系列、样式设置(当用户需要数据图表时读此文件)

  • references/standard-slides.md — 标准商务幻灯片函数库:标题页、目录页、

要点页、图文并排、数据页、章节分隔页、结尾页(当用户需要完整 PPT 结构时读此文件)

  • references/wps-compat.md — WPS 动画兼容性踩坑记录(当用户提到 WPS 或

动画效果异常时读此文件)

版本历史

共 1 个版本

  • v1.0.0 当前
    2026-03-29 22:56 安全 安全

安全检测

腾讯云安全 (Keen)

安全,无风险
查看报告

腾讯云安全 (Sanbu)

安全,无风险
查看报告

🔗 相关推荐

office-efficiency

Word / DOCX

ivangdavila
创建、检查和编辑 Microsoft Word 文档及 DOCX 文件,支持样式、编号、修订记录、表格、分节符及兼容性检查等功能。
★ 458 📥 152,709
office-efficiency

Excel / XLSX

ivangdavila
创建、检查和编辑 Microsoft Excel 工作簿及 XLSX 文件,支持可靠的公式、日期、类型、格式、重算及模板保留功能。
★ 382 📥 145,229
ai-agent

auto-browser

scottliu007
通过 Chrome 调试协议(CDP)自动化真实浏览器,实现导航、点击、填表、数据抓取、截图及多步流程。用户说“帮我在网页上操作”“打开浏览器”“帮我点”“帮我填”“帮我抓取”“帮我截图”“auto‑browser”时使用。
★ 0 📥 1,057