Skip to content

Instantly share code, notes, and snippets.

@jamesBan
Created April 13, 2017 06:15
Show Gist options
  • Select an option

  • Save jamesBan/1d8eb50c306b20cb64967f10fe12b6e4 to your computer and use it in GitHub Desktop.

Select an option

Save jamesBan/1d8eb50c306b20cb64967f10fe12b6e4 to your computer and use it in GitHub Desktop.
python 调用office 转换文档
import sys
import os
import glob
import win32com.client
def convert(files, formatType = 32):
powerpoint = win32com.client.Dispatch("PowerPoint.Application")
powerpoint.Visible = 1
for filename in files:
newname = os.path.splitext(filename)[0] + ".pdf"
deck = powerpoint.Presentations.Open(filename)
deck.SaveAs(newname, formatType)
deck.Close()
powerpoint.Quit()
files = glob.glob(os.path.join(sys.argv[1],"*.ppt*"))
convert(files)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment