如何使用Python自动生成简单的powerpoint示例?

时间:2014-12-13 08:56:31

标签: python powerpoint enthought canopy

我正在尝试使用Enthought Canopy重现赵教授提供的示例文件的结果:

http://www.shengdongzhao.com/shen_blog/how-to-automatically-create-powerpoint-slides-using-python/

我似乎遇到了其他人所拥有的(并且似乎仍然存在)相同的问题,您可以在链接博客文章下方的评论中看到。我意识到教授。赵提到错误可能是由于环境设置不正确。我认为它可能与未正确指向的环境变量有关。我尝试了下面的第一个答案,但似乎它甚至可以防止遮篷打开(我做错了)

How to add to the pythonpath in windows 7?

所以我要做的是:我在Canopy中打开他的脚本,然后运行MSO.py,然后运行MSPPT.py,然后运行MSPPTUtil.py。然后,当我运行CreateSlideExamples.py(更新了photo.JPG的目录)时,我只得到一张带表格的电源点幻灯片

enter image description here

控制台上堆满了以下错误列表:

%run C:/Users/dirkh_000/AppData/Local/Temp/Temp1_MSPPT.zip/MSO.py

%run "C:/Users/dirkh_000/Documents/Python scripts/Auto pp example/MSPPT.py"

%run "C:/Users/dirkh_000/Documents/Python scripts/Auto pp example/MSPPTUtil.py"

%run "C:/Users/dirkh_000/Documents/Python scripts/Auto pp example/CreateSlideExamples.py"
---------------------------------------------------------------------------
AttributeError                            Traceback (most recent call last)
C:\Users\dirkh_000\AppData\Local\Enthought\Canopy\App\appdata\canopy-1.4.1.1975.win-x86_64\lib\site-packages\IPython\utils\py3compat.pyc in execfile(fname, glob, loc)
    195             else:
    196                 filename = fname
--> 197             exec compile(scripttext, filename, 'exec') in glob, loc
    198     else:
    199         def execfile(fname, *where):

C:\Users\dirkh_000\Documents\Python scripts\Auto pp example\CreateSlideExamples.py in <module>()
     40 
     41 # step 3: show the slide
---> 42 presentation.create_show()
     43 
     44 # Now you can save the slide somewhere

C:\Users\dirkh_000\Documents\Python scripts\Auto pp example\MSPPTUtil.pyc in create_show(self, visible)
     45                         if visible:
     46                                 slide.select() #bring slide to front
---> 47                         slide.format_slide()
     48         def save_as(self, file_name):
     49                 self.presentation.SaveAs(file_name)

C:\Users\dirkh_000\Documents\Python scripts\Auto pp example\MSPPTUtil.pyc in format_slide(self)
     64                 self.slide.Select()
     65         def format_slide(self):
---> 66                 self.format_content()
     67                 self.format_title()
     68         def format_title(self):

C:\Users\dirkh_000\Documents\Python scripts\Auto pp example\MSPPTUtil.pyc in format_content(self)
    252                 if self.title:
    253                         #add title
--> 254                         title_range = slide.Shapes[0].TextFrame.TextRange
    255                         title_range.Text = self.title
    256                         title_range.Font.Bold = True

C:\Users\dirkh_000\AppData\Local\Enthought\Canopy\User\lib\site-packages\win32com\client\__init__.pyc in __getattr__(self, attr)
    463                 args=self._prop_map_get_.get(attr)
    464                 if args is None:
--> 465                         raise AttributeError("'%s' object has no attribute '%s'" % (repr(self), attr))
    466                 return self._ApplyTypes_(*args)
    467 

AttributeError: '<win32com.gen_py.Microsoft PowerPoint 15.0 Object Library.Shapes instance at 0x164276808>' object has no attribute '__getitem__' 

感谢任何帮助。我正在运行Windows 8.1,powerpoint 2013.

0 个答案:

没有答案