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)
python实现读取每一页PPT中的excel内容,将其写到excel表格中
最新推荐文章于 2024-09-26 11:55:47 发布