pptx-debug-workflow
它能做什么
这项技能是用 python-pptx 库制作 .pptx 演示文稿的谨慎方法,每个阶段都包含测试和调试。它适合编写制作演示文稿代码、并希望减少错误的人。
适用场景
- ✓当我正在编写创建 PowerPoint 演示文稿的 Python 代码的时候。
- ✓当演示文稿脚本失败,我需要找出原因的时候。
- ✓当我想在制作完整演示文稿之前,先确认 python-pptx 能正常工作的时候。
技能链接
https://github.com/HKUDS/AgentPilot/blob/main/openspace/benchmarks/gdpval/skills/pptx-debug-workflow/SKILL.md复制后粘贴给你的 AI(Claude、ChatGPT 或 Cursor),让它按照说明操作。
使用方法
最简单的方法:复制下面的消息,粘贴给你的 AI。它会读取这个技能并按说明操作。
可直接粘贴的消息
适用于 Claude Code、Codex 或 Cursor:在项目文件夹中运行,即可安装该技能。
下载 SKILL.md,放进智能体的技能文件夹。
可以这样问 AI
“请帮我编写一个 Python 脚本,制作包含图表和多张幻灯片的 PowerPoint。请先测试基础部分,以避免出错。”
每周 5 个新技能,1 分钟读完。
工作原理
AI 会确认 python-pptx 已安装,运行一个最小的测试演示文稿,然后把完整脚本写入文件,使错误能显示行号,并且脚本可以重新运行。
技术内容(原始 SKILL.md)
作者在 GitHub 上的英文原文。
PPTX Debugging Workflow
A systematic approach to creating and debugging PowerPoint presentations using the python-pptx library. This workflow ensures reliable presentation generation through iterative verification and error resolution.
Step 1: Verify Installation
Before writing any code, verify that python-pptx is installed:
pip show python-pptx
If not installed:
pip install python-pptx
Step 2: Test Minimal PPTX Creation
Create and run a minimal test script to verify the library works:
from pptx import Presentation
prs = Presentation()
slide = prs.slides.add_slide(prs.slide_layouts[0])
slide.shapes.title.text = "Test Slide"
prs.save("test.pptx")
print("Test presentation created successfully")
Run this first to confirm basic functionality before building complex presentations.
Step 3: Write Full Script to File
Always write your presentation script to a .py file instead of using heredoc or inline execution. This enables:
- Better error messages with line numbers
- Easier iteration and debugging
- Preserved state between error fixes
Example structure:
from pptx import Presentation
from pptx.util import Inches, Pt
from pptx.enum.shapes import MSO_SHAPE
from pptx.enum.chart import XL_CHART_TYPE, XL_LEGEND_POSITION
from pptx.chart.data import CategoryChartData
def create_presentation():
prs = Presentation()
# Build slides here
prs.save("output.pptx")
print("Presentation saved successfully")
if __name__ == "__main__":
create_presentation()
Step 4: Execute and Capture Full Traceback
Run the script with full error output:
python your_script.py 2>&1 | tee debug_output.log
This captures the complete Python traceback including:
- Error type and message
- Line numbers where errors occurred
- Stack trace for debugging
Step 5: Fix API Errors Iteratively
Common python-pptx API patterns to remember:
Chart Legend Positioning
Use XL_LEGEND_POSITION (NOT XL_CHART_TYPE) for legend positioning:
from pptx.enum.chart import XL_LEGEND_POSITION
chart.chart.has_legend = True
chart.chart.legend.position = XL_LEGEND_POSITION.RIGHT
Table Cell Access
Access table cells through row iteration pattern:
table = slide.shapes.add_table(rows=5, cols=4, left=Inches(1), top=Inches(2), width=Inches(6), height=Inches(3)).table
# Correct pattern - iterate through rows, then cells
for row_idx, row in enumerate(table.rows):
for cell_idx, cell in enumerate(row.cells):
cell.text = f"Row {row_idx}, Cell {cell_idx}"
# Or direct access
table.rows[0].cells[0].text = "Header"
Chart Data Format
For pie charts, use category-based data:
chart_data = CategoryChartData()
chart_data.categories = ['Category A', 'Category B', 'Category C']
chart_data.add_series('Series 1', (30, 45, 25))
x, y, cx, cy = Inches(2), Inches(2), Inches(6), Inches(4.5)
slide.shapes.add_chart(XL_CHART_TYPE.PIE, x, y, cx, cy, chart_data)
Step 6: Validate Output
After successful execution:
- Verify the
.pptxfile was created - Open in PowerPoint or compatible viewer
- Check that all slides, tables, and charts render correctly
Common Troubleshooting
| Issue | Solution |
|---|---|
| Module not found | pip install python-pptx |
| AttributeError on chart | Check XL_LEGEND_POSITION vs XL_CHART_TYPE |
| Table cell access fails | Use table.rows[row].cells[cell] pattern |
| Chart doesn't display | Verify chart_data format matches chart type |
| Import errors | Check enum imports from pptx.enum.* |
Quick Reference Script Template
from pptx import Presentation
from pptx.util import Inches, Pt
from pptx.enum.chart import XL_CHART_TYPE, XL_LEGEND_POSITION
from pptx.chart.data import CategoryChartData
def main():
prs = Presentation()
# Add title slide
slide = prs.slides.add_slide(prs.slide_layouts[0])
slide.shapes.title.text = "Title"
# Add content slide with table
slide = prs.slides.add_slide(prs.slide_layouts[1])
table = slide.shapes.add_table(3, 3, Inches(1), Inches(2), Inches(8), Inches(2)).table
for row in table.rows:
for cell in row.cells:
cell.text = "Data"
prs.save("presentation.pptx")
print("Done!")
if __name__ == "__main__":
main()
常见问题
为什么先测试一个最小的演示文稿?
它在投入大量时间制作完整演示文稿之前,确认库能够正常工作。
为什么要把脚本写入文件?
文件可以提供带行号的更清晰错误信息,并且便于编辑和重新运行。
演示文稿可以包含图表吗?
可以。示例从 python-pptx 导入了图表类型和图表数据类。
详情
热度
- GitHub 星标
- 7.8k
- 排名
- #12947
- 许可证
- MIT
- 更新时间
- 2026/11/1
评论
- …
同一仓库的更多技能
agentpilot
7.8k帮你的智能体准备任务并运行 AgentPilot 循环,逐步改进项目:循环会提出修改、测试修改并为其打分。
openspace
7.8k帮你的智能体设置 OpenSpace,这是一个用于存储和获取智能体技能的工具,并通过 MCP 将其连接到你的 AI 应用。
rsi-arena
7.8k帮你的智能体设置并运行标准 AI 基准测试,例如 AIME 和 Terminal-Bench,用来比较不同的改进方法。
experiment-guide
7.8k帮你的智能体规划小型实验、阅读实验结果并记录发现,同时研究如何改进一个程序。