Autocompletion for windows office win32 programming?

Apr 4, 2011 at 4:40 PM

Hi,

I need to write a number of Python scripts to automate some Microsoft Office tasks using Word, Powerpoint, etc. When using Pythonwin, I can get  completion when writing

import win32com.client as win32

word = win32.gencache.EnsureDispatch('Word.Application')
doc = word.Documents.Add()
word.Visible = True
rng = doc.Range(0,0)
rng.InsertAfter('Hacking Word with Python\r\n\r\n')

 

In other words, I can get code completion by typing word.<TAB>. Strangely, this does not work with Python tools for Visual Studio 2010. Am I missing something, or is this not designed to work this way?

Thanks!

 

 

Coordinator
Apr 4, 2011 at 9:09 PM

Do you see other win32* modules after you type "import "?  Using Enthought's Python distribution which includes win32com I see win32api but not win32com which may be the reason this isn't working for you - that's definitely a bug and I've opened it here: http://pytools.codeplex.com/workitem/88

But I wouldn't expect the completion to work against the word object because we won't know the members it has.  We could consider adding a feature to directly support intellisense agianst COM objects when using win32 though.  Is there an IDE that you use where that does work?  On the other hard it could work in the REPL where we can use live objects for completion.

Apr 5, 2011 at 2:25 PM
Yes, I seem some other win32 modules after the import statement in the
editor.

Currently, the only IDE I am aware of that allows this kind of
word/office intellisense completion is Pythonwin. There is an option in
the tools menu there for "COM Makepy" which I think has something to do
with it.

I heard about pytools at the last Python conference, and was excited
about it, since I primarily work on windows machines. It would be a
major help to me if you all implemented intellisense completion for
word/office scripting as I described below. The object model for office
is complicated and anything to help navigate it ( besides reading MSDN)
would be a big help!

Thanks!


On 4/4/2011 1:09 PM, dinov wrote:
> From: dinov
>
> Do you see other win32* modules after you type "import "? Using
> Enthought's Python distribution which includes win32com I see win32api
> but not win32com which may be the reason this isn't working for you -
> that's definitely a bug and I've opened it here:
> http://pytools.codeplex.com/workitem/88.
>
> But I wouldn't expect the completion to work against the word object
> because we won't know the members it has. We could consider adding a
> feature to directly support intellisense agianst COM objects when using
> win32 though. Is there an IDE that you use where that does work? On the
> other hard it could work in the REPL where we can use live objects for
> completion.
>
> Read the full discussion online
> <http://pytools.codeplex.com/discussions/252441#post591565>.
>
> To add a post to this discussion, reply to this email
> ([email removed]
> <mailto:[email removed]?subject=[pytools:252441]>)
>
> To start a new discussion for this project, email
> [email removed] <mailto:[email removed]>
>
> You are receiving this email because you subscribed to this discussion
> on CodePlex. You can unsubscribe
> <https://pytools.codeplex.com/discussions/252441/unsubscribe/> on
> CodePlex.com.
>
> Please note: Images and attachments will be removed from emails. Any
> posts to this discussion will also be available online at CodePlex.com
>
Coordinator
Apr 7, 2011 at 3:36 AM

Thanks for feedback - I've opened a feature request for this (http://pytools.codeplex.com/workitem/97).  I don't know that we'll get to this anytime too soon but it's a great idea and I don't want to lose track of it.