[IronPython] PowerPoint Automation
martmaly at exchange.microsoft.com
Thu Jun 30 14:28:20 PDT 2005
As for the "Visible" property. Reflecting on the Office Primary Interop
Assemblies shows that PowerPoint's Visible property has different type
than Word's one. Word is Boolean whereas PowerPoint has MsoTriState enum
It also seems that hiding the application window once visible is not
possible, as you have discovered. This seems to be limitation of
PowerPoint itself. I tried both setting the Visible to False, and also
Toggle (another value from the MsoTriState enum) but I failed on all
To work with slide ranges, using Python list won't work. Unfortunatelly,
there is no default conversion from the Python list data type to .NET
array type(s). However, you can use the .NET arrays directly. The
modified code would look as follows:
>>> import sys
>>> import Microsoft.Office.Interop.PowerPoint as Ppt
>>> app = Ppt.ApplicationClass()
>>> app.Visible = True
>>> app.Presentations.Open(r"C:\Documents and Settings\martmaly\My
>>> r=System.Array.CreateInstance(System.Int32, 5)
>>> range = app.Presentations.Item("IronPython.ppt").Slides.Range(r)
Using pure COM application from IronPython is possible, but to get .NET
interop to work, you will need to produce the .NET type information for
the COM library (provided the COM binary contains type library). You can
use "tlbimp" tool which is part of .NET SDK distribution to convert the
COM type library into .NET assembly.
Hope this helps
> kbond Wrote:
> I am still playing aound with the office Automation the last
> I try was PowerPoint and I was disapointed since I was
> willing to migrate a macro I have done a long time ago. This
> macro create a TOC to a ppt file.
> >>>>>>Import sys
> >>>>>> sys.LoadAssemblyByName("Microsoft.Office.Interop.PowerPoint")
> >>>>>> import Microsoft.Office.Interop.PowerPoint as msPPT pptApp =
> >>>>>>msPPT.ApplicationClass() pptApp.Visible
> ###### The value of this attribute is strange since for word
> it is a boulean############""
> >>>>>> pptApp.Visible = True # is working fine pptApp.Visible = False
> Application.Visible : Invalid reque st. Hiding the
> application window is not allowed.
> at input_12.Run(Frame frame)
> #### I am know inable to hide the PowerPoint application ########
> >>>>>> listOfSlide=[1,4]
> >>>>>> de)
> System.ArgumentException: Slides.Range : Illegal value for
> ^0. Bad type: expecte d 1D array of Variants, Integers,
> Longs, or Strings
> at input_31.Run(Frame frame)
> #### In order to specify a range I would expect to be able to
> give a list intead of an Array, am I wrong?###### Could you
> please advise on how I can select a range of slides?
> Is it possible to import a pure COM application with ironPython?
> Like I am doing using win32com.client.
> Thank you again for ironPython.
More information about the users-ironpython.com