from pptx import Presentation
from openpyxl import load_workbook
from docx import Document
def ppt_excel_to_word(ppt_file, excel_file, word_file):
# 读取PPT文件
ppt = Presentation(ppt_file)
# 读取Excel文件
excel = load_workbook(excel_file)
# 创建一个新的Word文档
doc = Document()
# 遍历PPT中的每一页
for slide in ppt.slides:
# 遍历幻灯片中的每一个形状
for shape in slide.shapes:
# 如果形状包含文本
if hasattr(shape, "text"):
# 将文本写入Word文档
doc.add_paragraph(shape.text)
# 遍历Excel中的每一页
for sheet in excel.sheetnames:
ws = excel[sheet]
# 遍历工作表中的每一行
for row in ws.iter_rows():
# 将单元格内容写入Word文档
row_data = [cell.value for cell in row]
doc.add_paragraph(" ".join(str(x) for x in row_data))
# 保存Word文档
doc.save(word_file)
# 使用示例
ppt_file = "example.pptx"
excel_file = "example.xlsx"
word_file = "output.docx"
ppt_excel_to_word(ppt_file, excel_file, word_file)
python实现读取每一页PPT中的内容,将其写到word文档中
最新推荐文章于 2024-08-29 19:30:55 发布