1

试图得到这个的工作版本

完全按照引用的代码使用,我收到以下错误:

Traceback (most recent call last):
  File "<pyshell#26>", line 1, in <module>
    ppoint()
  File "<pyshell#24>", line 9, in ppoint
    s1a = s1.Shapes[0].TextFrame.TextRange
  File "C:\Python27\lib\site-packages\win32com\client\__init__.py", line 465, in __getattr__
    raise AttributeError("'%s' object has no attribute '%s'" % (repr(self), attr))
AttributeError: '<win32com.gen_py.Microsoft PowerPoint 14.0 Object Library.Shapes instance at 0x36209528>' object has no attribute '__getitem__'

Win32com 导入正常 - 任何想法都非常感谢!

4

1 回答 1

0

我想我遇到了同样的问题。从 MSDN 查看 COM api 后,我发现它的语法有错误。您引用的页面中的正确代码应该是:

...
s1 = pres.Slides.Add(1, win32.constants.ppLayoutText)
sleep(1)
s1a = s1.Shapes(1).TextFrame.TextRange
s1a.Text = 'Python-to-%s Demo' % app
sleep(1)
s1b = s1.Shapes(2).TextFrame.TextRange
for i in RANGE:
     s1b.InsertAfter("Line %d\r\n" % i)
     sleep(1)
s1b.InsertAfter("\r\nTh-th-th-that's all folks!")
...

Shapes[1] 应该是 Shapes(1)。林茨伯格是对的。PowerPoint 集合的 COM API 应以 1 开头。

于 2014-02-15T04:32:49.167 回答