我想将某个文件夹下的 ppt 全部另存为 pdf,然后发现用 win32com 可以实现,写了这段代码,但是运行之后,只能将第一个 ppt 成功转成 pdf,接下来打开第二个 ppt 时就出错了: Traceback (most recent call last): File "D:_ppts\ppt_to_pdf.py", line 15, in <module> deck = powerpoint.Presentations.Open(ppt) File "<COMObject <unknown="">>", line 3, in Open com_error: (-2147352567, '\xb7\xa2\xc9\xfa\xd2\xe2\xcd\xe2\xa1\xa3', (0, None, None, None, 0, -2147467259), None)
#这是代码 #coding:utf-8 import win32com.client import glob,os
ppts = []
for i in os.walk('D:\_ppts'): ppts.extend(glob.glob('%s/*.ppt' %i[0]))
powerpoint = win32com.client.Dispatch("Powerpoint.Application") powerpoint.Visible = 1
for ppt in ppts:
newfile = ppt.split('\')[-1].strip('.ppt') + '.pdf'
p = powerpoint.Presentations.Open(ppt)
p.SaveAs('D:\_pdfs\%s' % newfile, 32)
p.Close()
powerpoint.Quit()
1
loading 2016-03-22 21:41:10 +08:00 via Android
a='\xb7\xa2\xc9\xfa\xd2\xe2\xcd\xe2\xa1\xa3'
print a |
2
loading 2016-03-22 21:42:43 +08:00 via Android
空格都被吞了,楼主贴到 gist 吧…
|
4
wangxl123 OP 找见错误了,是因为那第二个 ppt 自己损坏了打不开.......
|