pptx-manipulation by claude-office-skills/skills
npx skills add https://github.com/claude-office-skills/skills --skill pptx-manipulation此技能使用 python-pptx 库,支持以编程方式创建、编辑和操作 Microsoft PowerPoint (.pptx) 演示文稿。无需手动编辑即可创建包含文本、形状、图像、图表和表格的专业幻灯片。
示例提示:
from pptx import Presentation
from pptx.util import Inches, Pt
from pptx.enum.shapes import MSO_SHAPE
from pptx.enum.text import PP_ALIGN
# 创建新演示文稿
prs = Presentation()
# 或打开现有演示文稿
prs = Presentation('existing.pptx')
Presentation
├── slide_layouts (预定义布局)
├── slides (单个幻灯片)
│ ├── shapes (文本、图像、图表)
│ │ ├── text_frame (段落)
│ │ └── table (行、单元格)
│ └── placeholders (标题、内容占位符)
└── slide_masters (模板)
广告位招租
在这里展示您的产品或服务
触达数万 AI 开发者,精准高效
# 常见布局索引 (可能因模板而异)
TITLE_SLIDE = 0
TITLE_CONTENT = 1
SECTION_HEADER = 2
TWO_CONTENT = 3
COMPARISON = 4
TITLE_ONLY = 5
BLANK = 6
# 使用布局添加幻灯片
slide_layout = prs.slide_layouts[TITLE_CONTENT]
slide = prs.slides.add_slide(slide_layout)
slide_layout = prs.slide_layouts[0] # 标题幻灯片
slide = prs.slides.add_slide(slide_layout)
title = slide.shapes.title
subtitle = slide.placeholders[1]
title.text = "Quarterly Report"
subtitle.text = "Q4 2024 Performance Review"
# 使用占位符
body = slide.placeholders[1]
tf = body.text_frame
tf.text = "First bullet point"
# 添加更多段落
p = tf.add_paragraph()
p.text = "Second bullet point"
p.level = 0
p = tf.add_paragraph()
p.text = "Sub-bullet"
p.level = 1
from pptx.util import Inches, Pt
left = Inches(1)
top = Inches(2)
width = Inches(4)
height = Inches(1)
txBox = slide.shapes.add_textbox(left, top, width, height)
tf = txBox.text_frame
p = tf.paragraphs[0]
p.text = "Custom text box"
p.font.bold = True
p.font.size = Pt(18)
from pptx.enum.shapes import MSO_SHAPE
# 矩形
shape = slide.shapes.add_shape(
MSO_SHAPE.RECTANGLE,
Inches(1), Inches(2), # left, top
Inches(3), Inches(1.5) # width, height
)
shape.text = "Rectangle with text"
# 常见形状:
# MSO_SHAPE.RECTANGLE, ROUNDED_RECTANGLE
# MSO_SHAPE.OVAL, CHEVRON, ARROW_RIGHT
# MSO_SHAPE.CALLOUT_ROUNDED_RECTANGLE
# 添加图像
slide.shapes.add_picture(
'image.png',
Inches(1), Inches(2), # position
width=Inches(4) # auto height
)
# 或指定两个维度
slide.shapes.add_picture(
'logo.png',
Inches(8), Inches(0.5),
Inches(1.5), Inches(0.75)
)
# 创建表格
rows, cols = 4, 3
left = Inches(1)
top = Inches(2)
width = Inches(8)
height = Inches(2)
table = slide.shapes.add_table(rows, cols, left, top, width, height).table
# 设置列宽
table.columns[0].width = Inches(2)
table.columns[1].width = Inches(3)
table.columns[2].width = Inches(3)
# 添加表头
headers = ['Product', 'Q3 Sales', 'Q4 Sales']
for i, header in enumerate(headers):
cell = table.cell(0, i)
cell.text = header
cell.text_frame.paragraphs[0].font.bold = True
# 添加数据
data = [
['Widget A', '$10,000', '$12,500'],
['Widget B', '$8,000', '$9,200'],
['Widget C', '$15,000', '$18,000'],
]
for row_idx, row_data in enumerate(data, 1):
for col_idx, value in enumerate(row_data):
table.cell(row_idx, col_idx).text = value
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('Sales', (19.2, 21.4, 16.7, 23.8))
chart_data.add_series('Expenses', (12.1, 15.3, 14.2, 18.1))
# 添加图表
x, y, cx, cy = Inches(1), Inches(2), Inches(8), Inches(4)
chart = slide.shapes.add_chart(
XL_CHART_TYPE.COLUMN_CLUSTERED,
x, y, cx, cy, chart_data
).chart
# 自定义
chart.has_legend = True
chart.legend.include_in_layout = False
from pptx.dml.color import RGBColor
run = p.runs[0]
run.font.name = 'Arial'
run.font.size = Pt(24)
run.font.bold = True
run.font.italic = True
run.font.color.rgb = RGBColor(0x00, 0x66, 0xCC)
from pptx.dml.color import RGBColor
shape.fill.solid()
shape.fill.fore_color.rgb = RGBColor(0x00, 0x80, 0x00)
shape.line.color.rgb = RGBColor(0x00, 0x00, 0x00)
shape.line.width = Pt(2)
from pptx.enum.text import PP_ALIGN
p.alignment = PP_ALIGN.CENTER # LEFT, RIGHT, JUSTIFY
def create_deck(title, slides_content):
prs = Presentation()
# 标题幻灯片
slide = prs.slides.add_slide(prs.slide_layouts[0])
slide.shapes.title.text = title
# 内容幻灯片
for slide_data in slides_content:
slide = prs.slides.add_slide(prs.slide_layouts[1])
slide.shapes.title.text = slide_data['title']
body = slide.placeholders[1]
tf = body.text_frame
for i, point in enumerate(slide_data['points']):
if i == 0:
tf.text = point
else:
p = tf.add_paragraph()
p.text = point
return prs
def add_bar_chart(slide, title, categories, values):
from pptx.chart.data import CategoryChartData
from pptx.enum.chart import XL_CHART_TYPE
chart_data = CategoryChartData()
chart_data.categories = categories
chart_data.add_series('Values', values)
chart = slide.shapes.add_chart(
XL_CHART_TYPE.BAR_CLUSTERED,
Inches(1), Inches(2),
Inches(8), Inches(4),
chart_data
).chart
chart.chart_title.text_frame.text = title
return chart
from pptx import Presentation
from pptx.util import Inches, Pt
prs = Presentation()
# 幻灯片 1:标题
slide = prs.slides.add_slide(prs.slide_layouts[0])
slide.shapes.title.text = "StartupX"
slide.placeholders[1].text = "Revolutionizing Document Processing"
# 幻灯片 2:问题
slide = prs.slides.add_slide(prs.slide_layouts[1])
slide.shapes.title.text = "The Problem"
body = slide.placeholders[1].text_frame
body.text = "Manual document processing costs businesses $1T annually"
p = body.add_paragraph()
p.text = "Average worker spends 20% of time on document tasks"
p.level = 1
# 幻灯片 3:解决方案
slide = prs.slides.add_slide(prs.slide_layouts[1])
slide.shapes.title.text = "Our Solution"
body = slide.placeholders[1].text_frame
body.text = "AI-powered document automation"
body.add_paragraph().text = "90% faster processing"
body.add_paragraph().text = "99.5% accuracy"
body.add_paragraph().text = "Works with existing tools"
# 幻灯片 4:市场
slide = prs.slides.add_slide(prs.slide_layouts[5]) # Title only
slide.shapes.title.text = "Market Opportunity: $50B by 2028"
# 添加图表
from pptx.chart.data import CategoryChartData
from pptx.enum.chart import XL_CHART_TYPE
data = CategoryChartData()
data.categories = ['2024', '2025', '2026', '2027', '2028']
data.add_series('Market Size ($B)', [30, 35, 40, 45, 50])
slide.shapes.add_chart(
XL_CHART_TYPE.LINE,
Inches(1), Inches(1.5),
Inches(8), Inches(5),
data
)
prs.save('pitch_deck.pptx')
from pptx import Presentation
from pptx.util import Inches, Pt
prs = Presentation()
# 标题幻灯片
slide = prs.slides.add_slide(prs.slide_layouts[0])
slide.shapes.title.text = "Sales Performance Report"
slide.placeholders[1].text = "Q4 2024"
# 数据幻灯片
slide = prs.slides.add_slide(prs.slide_layouts[5])
slide.shapes.title.text = "Regional Performance"
# 创建表格
table = slide.shapes.add_table(5, 4, Inches(0.5), Inches(1.5), Inches(9), Inches(4)).table
# 表头
headers = ['Region', 'Revenue', 'Growth', 'Target']
for i, h in enumerate(headers):
table.cell(0, i).text = h
table.cell(0, i).text_frame.paragraphs[0].font.bold = True
# 数据
data = [
['North America', '$5.2M', '+15%', 'Met'],
['Europe', '$3.8M', '+12%', 'Met'],
['Asia Pacific', '$2.9M', '+28%', 'Exceeded'],
['Latin America', '$1.1M', '+8%', 'Below'],
]
for row_idx, row_data in enumerate(data, 1):
for col_idx, value in enumerate(row_data):
table.cell(row_idx, col_idx).text = value
prs.save('sales_report.pptx')
pip install python-pptx
每周安装数
101
仓库
GitHub 星标数
7
首次出现
3 天前
安全审计
安装于
claude-code78
gemini-cli47
github-copilot47
codex47
opencode47
cursor47
This skill enables programmatic creation, editing, and manipulation of Microsoft PowerPoint (.pptx) presentations using the python-pptx library. Create professional slides with text, shapes, images, charts, and tables without manual editing.
Example prompts:
from pptx import Presentation
from pptx.util import Inches, Pt
from pptx.enum.shapes import MSO_SHAPE
from pptx.enum.text import PP_ALIGN
# Create new presentation
prs = Presentation()
# Or open existing
prs = Presentation('existing.pptx')
Presentation
├── slide_layouts (predefined layouts)
├── slides (individual slides)
│ ├── shapes (text, images, charts)
│ │ ├── text_frame (paragraphs)
│ │ └── table (rows, cells)
│ └── placeholders (title, content)
└── slide_masters (templates)
# Common layout indices (may vary by template)
TITLE_SLIDE = 0
TITLE_CONTENT = 1
SECTION_HEADER = 2
TWO_CONTENT = 3
COMPARISON = 4
TITLE_ONLY = 5
BLANK = 6
# Add slide with layout
slide_layout = prs.slide_layouts[TITLE_CONTENT]
slide = prs.slides.add_slide(slide_layout)
slide_layout = prs.slide_layouts[0] # Title slide
slide = prs.slides.add_slide(slide_layout)
title = slide.shapes.title
subtitle = slide.placeholders[1]
title.text = "Quarterly Report"
subtitle.text = "Q4 2024 Performance Review"
# Using placeholder
body = slide.placeholders[1]
tf = body.text_frame
tf.text = "First bullet point"
# Add more paragraphs
p = tf.add_paragraph()
p.text = "Second bullet point"
p.level = 0
p = tf.add_paragraph()
p.text = "Sub-bullet"
p.level = 1
from pptx.util import Inches, Pt
left = Inches(1)
top = Inches(2)
width = Inches(4)
height = Inches(1)
txBox = slide.shapes.add_textbox(left, top, width, height)
tf = txBox.text_frame
p = tf.paragraphs[0]
p.text = "Custom text box"
p.font.bold = True
p.font.size = Pt(18)
from pptx.enum.shapes import MSO_SHAPE
# Rectangle
shape = slide.shapes.add_shape(
MSO_SHAPE.RECTANGLE,
Inches(1), Inches(2), # left, top
Inches(3), Inches(1.5) # width, height
)
shape.text = "Rectangle with text"
# Common shapes:
# MSO_SHAPE.RECTANGLE, ROUNDED_RECTANGLE
# MSO_SHAPE.OVAL, CHEVRON, ARROW_RIGHT
# MSO_SHAPE.CALLOUT_ROUNDED_RECTANGLE
# Add image
slide.shapes.add_picture(
'image.png',
Inches(1), Inches(2), # position
width=Inches(4) # auto height
)
# Or specify both dimensions
slide.shapes.add_picture(
'logo.png',
Inches(8), Inches(0.5),
Inches(1.5), Inches(0.75)
)
# Create table
rows, cols = 4, 3
left = Inches(1)
top = Inches(2)
width = Inches(8)
height = Inches(2)
table = slide.shapes.add_table(rows, cols, left, top, width, height).table
# Set column widths
table.columns[0].width = Inches(2)
table.columns[1].width = Inches(3)
table.columns[2].width = Inches(3)
# Add headers
headers = ['Product', 'Q3 Sales', 'Q4 Sales']
for i, header in enumerate(headers):
cell = table.cell(0, i)
cell.text = header
cell.text_frame.paragraphs[0].font.bold = True
# Add data
data = [
['Widget A', '$10,000', '$12,500'],
['Widget B', '$8,000', '$9,200'],
['Widget C', '$15,000', '$18,000'],
]
for row_idx, row_data in enumerate(data, 1):
for col_idx, value in enumerate(row_data):
table.cell(row_idx, col_idx).text = value
from pptx.chart.data import CategoryChartData
from pptx.enum.chart import XL_CHART_TYPE
# Chart data
chart_data = CategoryChartData()
chart_data.categories = ['Q1', 'Q2', 'Q3', 'Q4']
chart_data.add_series('Sales', (19.2, 21.4, 16.7, 23.8))
chart_data.add_series('Expenses', (12.1, 15.3, 14.2, 18.1))
# Add chart
x, y, cx, cy = Inches(1), Inches(2), Inches(8), Inches(4)
chart = slide.shapes.add_chart(
XL_CHART_TYPE.COLUMN_CLUSTERED,
x, y, cx, cy, chart_data
).chart
# Customize
chart.has_legend = True
chart.legend.include_in_layout = False
from pptx.dml.color import RGBColor
run = p.runs[0]
run.font.name = 'Arial'
run.font.size = Pt(24)
run.font.bold = True
run.font.italic = True
run.font.color.rgb = RGBColor(0x00, 0x66, 0xCC)
from pptx.dml.color import RGBColor
shape.fill.solid()
shape.fill.fore_color.rgb = RGBColor(0x00, 0x80, 0x00)
shape.line.color.rgb = RGBColor(0x00, 0x00, 0x00)
shape.line.width = Pt(2)
from pptx.enum.text import PP_ALIGN
p.alignment = PP_ALIGN.CENTER # LEFT, RIGHT, JUSTIFY
def create_deck(title, slides_content):
prs = Presentation()
# Title slide
slide = prs.slides.add_slide(prs.slide_layouts[0])
slide.shapes.title.text = title
# Content slides
for slide_data in slides_content:
slide = prs.slides.add_slide(prs.slide_layouts[1])
slide.shapes.title.text = slide_data['title']
body = slide.placeholders[1]
tf = body.text_frame
for i, point in enumerate(slide_data['points']):
if i == 0:
tf.text = point
else:
p = tf.add_paragraph()
p.text = point
return prs
def add_bar_chart(slide, title, categories, values):
from pptx.chart.data import CategoryChartData
from pptx.enum.chart import XL_CHART_TYPE
chart_data = CategoryChartData()
chart_data.categories = categories
chart_data.add_series('Values', values)
chart = slide.shapes.add_chart(
XL_CHART_TYPE.BAR_CLUSTERED,
Inches(1), Inches(2),
Inches(8), Inches(4),
chart_data
).chart
chart.chart_title.text_frame.text = title
return chart
from pptx import Presentation
from pptx.util import Inches, Pt
prs = Presentation()
# Slide 1: Title
slide = prs.slides.add_slide(prs.slide_layouts[0])
slide.shapes.title.text = "StartupX"
slide.placeholders[1].text = "Revolutionizing Document Processing"
# Slide 2: Problem
slide = prs.slides.add_slide(prs.slide_layouts[1])
slide.shapes.title.text = "The Problem"
body = slide.placeholders[1].text_frame
body.text = "Manual document processing costs businesses $1T annually"
p = body.add_paragraph()
p.text = "Average worker spends 20% of time on document tasks"
p.level = 1
# Slide 3: Solution
slide = prs.slides.add_slide(prs.slide_layouts[1])
slide.shapes.title.text = "Our Solution"
body = slide.placeholders[1].text_frame
body.text = "AI-powered document automation"
body.add_paragraph().text = "90% faster processing"
body.add_paragraph().text = "99.5% accuracy"
body.add_paragraph().text = "Works with existing tools"
# Slide 4: Market
slide = prs.slides.add_slide(prs.slide_layouts[5]) # Title only
slide.shapes.title.text = "Market Opportunity: $50B by 2028"
# Add chart
from pptx.chart.data import CategoryChartData
from pptx.enum.chart import XL_CHART_TYPE
data = CategoryChartData()
data.categories = ['2024', '2025', '2026', '2027', '2028']
data.add_series('Market Size ($B)', [30, 35, 40, 45, 50])
slide.shapes.add_chart(
XL_CHART_TYPE.LINE,
Inches(1), Inches(1.5),
Inches(8), Inches(5),
data
)
prs.save('pitch_deck.pptx')
from pptx import Presentation
from pptx.util import Inches, Pt
prs = Presentation()
# Title slide
slide = prs.slides.add_slide(prs.slide_layouts[0])
slide.shapes.title.text = "Sales Performance Report"
slide.placeholders[1].text = "Q4 2024"
# Data slide
slide = prs.slides.add_slide(prs.slide_layouts[5])
slide.shapes.title.text = "Regional Performance"
# Create table
table = slide.shapes.add_table(5, 4, Inches(0.5), Inches(1.5), Inches(9), Inches(4)).table
# Headers
headers = ['Region', 'Revenue', 'Growth', 'Target']
for i, h in enumerate(headers):
table.cell(0, i).text = h
table.cell(0, i).text_frame.paragraphs[0].font.bold = True
# Data
data = [
['North America', '$5.2M', '+15%', 'Met'],
['Europe', '$3.8M', '+12%', 'Met'],
['Asia Pacific', '$2.9M', '+28%', 'Exceeded'],
['Latin America', '$1.1M', '+8%', 'Below'],
]
for row_idx, row_data in enumerate(data, 1):
for col_idx, value in enumerate(row_data):
table.cell(row_idx, col_idx).text = value
prs.save('sales_report.pptx')
pip install python-pptx
Weekly Installs
101
Repository
GitHub Stars
7
First Seen
3 days ago
Security Audits
Gen Agent Trust HubPassSocketFailSnykPass
Installed on
claude-code78
gemini-cli47
github-copilot47
codex47
opencode47
cursor47
Gmail过滤器创建教程 - 使用Google Workspace CLI自动分类邮件与添加标签
6,700 周安装
Rust调用关系图生成器 - 可视化函数调用层次结构,提升代码分析效率
539 周安装
parallel-web-extract:并行网页内容提取工具,高效抓取网页数据
595 周安装
腾讯云CloudBase AI模型Web技能:前端调用混元/DeepSeek模型,实现流式文本生成
560 周安装
Apollo Connectors 模式助手:GraphQL API 连接器开发与集成指南
565 周安装
GitHub Trending 趋势分析工具:实时发现热门项目、技术洞察与开源机会
556 周安装
GSAP React 集成教程:useGSAP Hook 动画库与 React 组件开发指南
546 周安装