往ppt中写入数据

import win32com
import win32com.client
import time

def makePPT(path):
ppt = win32com.client.Dispatch(‘PowerPoint.Application’)
ppt.Visible = True

#增加一个文件
pptFile = ppt.Presentations.Add()

#创建页
page1 = pptFile.Slides.Add(1,1)
t1 = page1.Shapes[0].TextFrame.TextRange
t1.Text = 'sunck'
t2 = page1.Shapes[1].TextFrame.TextRange
t2.Text = 'sunck is good man'

page2 = pptFile.Slides.Add(2,1)  #2代表第二页ppt
t1 = page2.Shapes[0].TextFrame.TextRange
t1.Text = 'keyi'
t2 = page2.Shapes[1].TextFrame.TextRange
t2.Text = 'keyi is good man'

page3 = pptFile.Slides.Add(3,2)  #2代表ppt的样式
t1 = page3.Shapes[0].TextFrame.TextRange
t1.Text = '小王'
t2 = page3.Shapes[1].TextFrame.TextRange
t2.Text = '小王你好'

#保存
pptFile.SaveAs(path)
time.sleep(10)
pptFile.Close()
ppt.Quit()

path = r’c:\Users\HP_SSE\Desktop\pp.ppt’
makePPT(path)

猜你喜欢

转载自blog.csdn.net/weixin_42669661/article/details/81483339