用途:该技能用于以 Python 的 python-pptx 库程序化创建、编辑和自动化 PowerPoint(.pptx)演示文稿,覆盖版式、主题、内容、图表与可视化。
主要能力:新建演示文稿与模板、元数据与页面配置;添加、复制、删除、重排幻灯片并使用预定义版式;处理文本、形状、图片、表格、图表、SmartArt、超链接;设置主题、配色、字体、填充、边框、效果;支持切换、动画、嵌入对象、视频/音频、批注;可基于数据批量生成幻灯片。
使用方式:需安装依赖,命令为 pip install python-pptx 或 uv pip install python-pptx。常用导入包括 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、from pptx.chart.data import CategoryChartData、from pptx.enum.chart import XL_CHART_TYPE。典型流程为初始化 Presentation、设置尺寸与元数据、添加标题页和内容页、插入图片/图表/表格、保存为 .pptx。示例:prs = Presentation();prs.slide_width = Inches(10);prs.slide_height = Inches(7.5);slide = prs.slides.add_slide(prs.slide_layouts[0]);slide.shapes.title.text = "Q4 Business Review";prs.save('presentation.pptx')。图表示例:chart_data = CategoryChartData();chart_data.categories = ['Q1', 'Q2', 'Q3', 'Q4'];chart_data.add_series('2025', (9.5, 10.8, 11.2, 13.1));slide.shapes.add_chart(XL_CHART_TYPE.COLUMN_CLUSTERED, Inches(1), Inches(2), Inches(8), Inches(4.5), chart_data)。
适用场景:从数据生成业务演示、自动化报告、从数据库批量生成幻灯片、模板化品牌演示、含图表与图片的教学内容、文档转幻灯片。
限制:依赖 python-pptx;复杂动画、切换等高级特性支持有限;图片需注意路径与尺寸;文本可能溢出;文件过大需压缩图片;具体收费与平台支持暂未提供。