# 创建新的PowerPoint文档
# pptSel = ppt.Presentations.Add()
# 打开一个已有的PowerPoint文档
import win32com, time
from win32com.client import Dispatch
import os
from PIL import Image
from datetime import datetime
import xlwings as xw
img_dir = r"E:\code\dock_project\excel_image\ppt_images"
excel_dir = r"E:\code\dock_project\excel_image\excel_files"
day = datetime.now().strftime('%Y%m%d')
ppt = Dispatch('PowerPoint.Application')
# 或者使用下面的方法,使用启动独立的进程:
# ppt = DispatchEx('PowerPoint.Application')
# 如果不声明以下属性,运行的时候会显示的打开word
ppt.Visible = True # 后台运行
ppt.DisplayAlerts = 0 # 不显示,不警告
pptSel = ppt.Presentations.Open(r"E:\code\dock_project\excel_image\2022.ppt")
template = ppt.Presentations.Open(r"E:\code\dock_project\excel_image\template.ppt")
#复制粘贴第一页
# template.Slides(1).Copy()
# time.sleep(5)
# pptSel.Slides.Paste()
#
for i in range(len(bu_list)*4):
template.Slides(2).Copy()
a = 0
while not a:
try:
a = pptSel.Slides.Paste()
except:
time.sleep(0.5)
print(i,a)
print('success copy')
pptSel.Slides(1).Shapes("Text Box 2").TextFrame.TextRange.Text='''
Y2022 WK09 Sales Meeting
2022 年 03月01日
'''
pptSel.Slides(2).Shapes("標題 3").TextFrame.TextRange.Text=''' BU'''
pptSel.Slides(2).Shapes.AddPicture(FileName=r"E:\code\dock_project\220324.png", LinkToFile=False, SaveWithDocument=True, Left=15, Top=90, Width=748, Height=420)
pptSel.SaveAs(os.getcwd() + "\\" + "2022_RPA.ppt") # 另存为
pptSel.Close() # 关闭 PowerPoint 文档
template.Close()
ppt.Quit() # 关闭 office
print(bu_sheet_dict)
print('----------------->')
PowerPoint.Application win32 操作ppt 复制 新建 插入图片
最新推荐文章于 2023-10-28 09:50:58 发布