| name | wps-ppt-to-doc |
| description | PPT转Word文档。把PPT演示文稿的内容整理成结构化的Word文档,
标题变章节、要点变段落、表格也保留,方便会后分发阅读或归档留存。
用于帮助用户将PPT转为文档。当用户提到PPT转Word、PPT导出文档时触发。
Converts PPT presentations to structured Word documents.
|
| license | MIT |
| user-invocable | true |
| argument-hint | [PPT文件路径] |
| allowed-tools | Read, Grep, Glob, Bash, Write, Edit |
| metadata | {"author":"BWKYD","title":"PPT转Word","description_zh":"将PPT内容整理成结构化的Word文档,方便分发和归档","tags":["PPT","Word","转换","文档","WPS"],"version":"1.0.1","license":"MIT"} |
PPT转Word工具
PPT → 结构化Word文档。会后分发、归档必备。
When to Use
- PPT内容需要转为Word文档
- 会议演示材料需要文字版分发
- PPT归档需要可搜索的文档格式
- 用户说"把PPT转成Word""导出PPT文字内容"
When NOT to Use
- Word转PPT → 使用
wps-ppt-outline + wps-ppt-gen
- 只需提取文字 → 直接读取PPT文本
转换模式
[1] 完整模式 → 标题+内容+图表描述+备注
[2] 精简模式 → 仅标题+要点
[3] 讲义模式 → 含幻灯片缩略描述+详细文字
工作流程
Step 1: 读取PPT
from pptx import Presentation
from docx import Document
from docx.shared import Pt, Cm
from docx.enum.text import WD_ALIGN_PARAGRAPH
from docx.oxml.ns import qn
import os
def ppt_to_word(ppt_path, mode='完整', output_path=None):
"""PPT转Word"""
prs = Presentation(ppt_path)
doc = Document()
section = doc.sections[0]
section.top_margin = Cm(2.54)
section.bottom_margin = Cm(2.54)
section.left_margin = Cm(3.18)
section.right_margin = Cm(3.18)
def set_font(run, name='宋体', size=12, bold=False):
run.font.size = Pt(size)
run.font.name = name
run._element.rPr.rFonts.set(qn('w:eastAsia'), name)
run.bold = bold
first_title = ''
if prs.slides:
for shape in prs.slides[0].shapes:
if shape.has_text_frame and shape == prs.slides[0].shapes.title:
first_title = shape.text_frame.text
break
p = doc.add_paragraph()
p.alignment = WD_ALIGN_PARAGRAPH.CENTER
run = p.add_run(first_title or 'PPT文档内容')
set_font(run, '黑体', , )
doc.add_paragraph()
i, slide (prs.slides):
slide_title =
slide_texts = []
has_notes =
notes_text =
shape slide.shapes:
shape.has_text_frame:
shape == slide.shapes.title:
slide_title = shape.text_frame.text.strip()
:
para shape.text_frame.paragraphs:
text = para.text.strip()
text:
slide_texts.append(text)
slide.has_notes_slide:
notes = slide.notes_slide.notes_text_frame.text.strip()
notes:
has_notes =
notes_text = notes
i > slide_title != first_title:
p = doc.add_paragraph()
run = p.add_run()
set_font(run, , , )
p.paragraph_format.space_before = Pt()
p.paragraph_format.space_after = Pt()
text slide_texts:
p = doc.add_paragraph()
p.paragraph_format.first_line_indent = Pt()
run = p.add_run(text)
set_font(run, , )
mode == has_notes:
p = doc.add_paragraph()
run = p.add_run()
set_font(run, , )
shape slide.shapes:
shape.has_chart:
p = doc.add_paragraph()
run = p.add_run()
set_font(run, , )
shape.has_table:
table = shape.table
doc_table = doc.add_table(rows=(table.rows),
cols=(table.columns))
ri, row (table.rows):
ci, cell (row.cells):
doc_table.cell(ri, ci).text = cell.text
output_path:
base = os.path.splitext(os.path.basename(ppt_path))[]
output_path =
doc.save(output_path)
os.path.abspath(output_path)
Step 2: 交付
- 生成结构化Word文档
- 保留标题层级和内容要点
- 标注原PPT中图表/表格位置
示例
/wps-ppt-to-doc 把quarterly_review.pptx转成Word文档
/wps-ppt-to-doc 只提取PPT的标题和要点到Word
/wps-ppt-to-doc 把培训PPT转成学员讲义