Skip to content

Instantly share code, notes, and snippets.

@goghvanmr
Created December 10, 2011 04:39
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save goghvanmr/1454600 to your computer and use it in GitHub Desktop.
Save goghvanmr/1454600 to your computer and use it in GitHub Desktop.
Simple Wallpaper maker using PPT Com API
# -*- coding: utf-8 -*-
import win32com.client as win32
fileDir = 'D:/Documents/Python/pythonic/python_ppt/'
fileName = 'wallpaper.pptx'
def add_wallpaper_slides():
text = raw_input('Input the text:')
# Open Powerpoint Application
app = 'PowerPoint'
pptApp = win32.Dispatch('%s.Application' % app)
# Open the existing wallpaper ppt
pptWp = pptApp.Presentations.Open('%s%s' % (fileDir, fileName))
# Copy the last slide and make a paste
slides = pptWp.Slides
count = slides.Count
slides[0].Copy()
slides.Paste(count+1)
# Make change to last slide
lastSlide = pptWp.Slides[count]
lastSlide.Shapes[0].TextFrame.TextRange.Text = text
# Save as jpg img
imgFileName = '_'.join(text.split())
lastSlide.Export('%s%s.jpg' % (fileDir, imgFileName), 'JPG')
# Save the ppt and quit
pptWp.Save()
pptWp.Close()
pptApp.Quit()
if __name__ == '__main__':
add_wallpaper_slides()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment