__win32com powerpoint对象库中的getitem\uuu错误

2024-09-30 18:13:09 发布

您现在位置:Python中文网/ 问答频道 /正文

正在尝试获取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导入的很好-任何想法都非常感谢!在


Tags: noinpy版本objectlineattributethis
1条回答
网友
1楼 · 发布于 2024-09-30 18:13:09

我想我也遇到了同样的问题。在从MSDN中检查了comapi之后,我发现语法有错误。引用页面中的正确代码应为:

...
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)。林德斯伯格是对的。PowerPoint集合的COM API应以1开头。在

相关问题 更多 >