python实现读取每一页PPT中的excel内容,将其写到excel表格中

from pptx import Presentation
from openpyxl import load_workbook, Workbook

def ppt_excel_to_excel(ppt_file, excel_file, output_file):
    # 读取PPT文件
    ppt = Presentation(ppt_file)
    # 读取Excel文件
    excel = load_workbook(excel_file)
    # 创建一个新的Excel表格
    new_excel = Workbook()
    new_sheet = new_excel.active

    # 遍历PPT中的每一页
    for slide in ppt.slides:
        # 遍历幻灯片中的每一个形状
        for shape in slide.shapes:
            # 如果形状包含文本
            if hasattr(shape, "text"):
                # 将文本写入Excel表格的新行
                new_sheet.append([shape.text])

    # 遍历Excel中的每一页
    for sheet in excel.sheetnames:
        ws = excel[sheet]
        # 遍历工作表中的每一行
        for row in ws.iter_rows():
            # 将单元格内容写入Excel表格的新行
            row_data = [cell.value for cell in row]
            new_sheet.append(row_data)

    # 保存Excel表格
    new_excel.save(output_file)

# 使用示例
ppt_file = "example.pptx"
excel_file = "example.xlsx"
output_file = "output.xlsx"
ppt_excel_to_excel(ppt_file, excel_file, output_file)
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值