V2EX = way to explore
V2EX 是一个关于分享和探索的地方
现在注册
已注册用户请  登录
推荐学习书目
Learn Python the Hard Way
Python Sites
PyPI - Python Package Index
http://diveintopython.org/toc/index.html
Pocoo
值得关注的项目
PyPy
Celery
Jinja2
Read the Docs
gevent
pyenv
virtualenv
Stackless Python
Beautiful Soup
结巴中文分词
Green Unicorn
Sentry
Shovel
Pyflakes
pytest
Python 编程
pep8 Checker
Styles
PEP 8
Google Python Style Guide
Code Style from The Hitchhiker's Guide
wangxl123
V2EX  ›  Python

关于 win32com 将 ppt 另存为 pdf 的问题

  •  
  •   wangxl123 · 2016-03-22 21:36:49 +08:00 · 3155 次点击
    这是一个创建于 2961 天前的主题,其中的信息可能已经有所发展或是发生改变。

    我想将某个文件夹下的 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()

    4 条回复    2016-03-24 17:51:02 +08:00
    loading
        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
    loading
        2
    loading  
       2016-03-22 21:42:43 +08:00 via Android
    空格都被吞了,楼主贴到 gist 吧…
    wangxl123
        3
    wangxl123  
    OP
       2016-03-22 22:11:50 +08:00 via iPhone
    @loading print 出来四个字:“发生意外”.....
    wangxl123
        4
    wangxl123  
    OP
       2016-03-24 17:51:02 +08:00 via iPhone
    找见错误了,是因为那第二个 ppt 自己损坏了打不开.......
    关于   ·   帮助文档   ·   博客   ·   API   ·   FAQ   ·   我们的愿景   ·   实用小工具   ·   2391 人在线   最高记录 6543   ·     Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 · 26ms · UTC 12:43 · PVG 20:43 · LAX 05:43 · JFK 08:43
    Developed with CodeLauncher
    ♥ Do have faith in what you're doing.