尝试获取this
的工作版本使用与引用完全相同的代码,我收到以下错误:
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导入正常 - 任何想法都非常感激!
答案 0 :(得分: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!")
...
形状[1]应该是形状(1)。而Rindsberg是对的。 PowerPoint集合的COM API应以1开头。