pywin32 - word object reference module - automating form filling

B

Brendan

I was hoping to use pywin32 to automate some rather tedious filling in
of Word forms. I thought the process would be analogous to dealing
with xml documents or DOM but find myself somewhat lost in the word
object reference manual (http://msdn.microsoft.com/en-us/library/
bb244515.aspx) . I was hoping to easily load all document objects
into a list so that I could poke around, examine and experiment with
them. So far all I have managed to do is load the page content as a
string, not particularly helpful.

Could someone please point me in the right direction?

Also, help, __doc__ and dir do not return anything meaningful(to me
anyway) or helpful. There seem to be no exposed methods or properties.
e.g. I have a word document object:
wd = wordapp.Documents.Open('blah.dic')
But:['_ApplyTypes_', '_FlagAsMethod', '_LazyAddAttr_', '_NewEnum',
'_Release_', '__AttrToID__', '__LazyMap__', '__call__', '__cmp__',
'__doc__', '__getattr__', '__getitem__', '__init__', '__int__',
'__len__', '__module__', '__nonzero__', '__repr__', '__setattr__',
'__setitem__', '__str__', '_builtMethods_', '_enum_',
'_find_dispatch_type_', '_get_good_object_',
'_get_good_single_object_', '_lazydata_', '_make_method_',
'_mapCachedItems_', '_oleobj_', '_olerepr_', '_print_details_',
'_proc_', '_unicode_to_string_', '_username_', '_wrap_dispatch_']

And:
The dynamic class used as a last resort.
The purpose of this overriding of dynamic.CDispatch is to
perpetuate the policy
of using the makepy generated wrapper Python class instead of
dynamic.CDispatch
if/when possible.

Furthermore:Help on instance of CDispatch in module win32com.client object:

class instance(object)
| instance(class[, dict])
|
| Create an instance without calling its __init__() method.
| The class must be a classic class.
| If present, dict must be a dictionary or None.
|
| Methods defined here:
|
| __abs__(...)
| x.__abs__() <==> abs(x)

~ ~ snip ~ ~

| __truediv__(...)
| x.__truediv__(y) <==> x/y
|
| __xor__(...)
| x.__xor__(y) <==> x^y
|
| next(...)
| x.next() -> the next value, or raise StopIteration
|
|
----------------------------------------------------------------------
| Data and other attributes defined here:
|
| __new__ = <built-in method __new__ of type object at 0x1E1C74D0>
| T.__new__(S, ...) -> a new object with type S, a subtype of T


What gives?
 
B

Brendan

I was hoping to use pywin32 to automate some rather tedious filling in
of Word forms. I thought the process would be analogous to dealing
with xml documents or DOM but find myself somewhat lost in the word
object reference manual (http://msdn.microsoft.com/en-us/library/
bb244515.aspx) .  I was hoping to easily load all document objects
into a list so that I could poke around, examine and experiment with
them. So far all I have managed to do is load the page content as a
string, not particularly helpful.

Could someone please point me in the right direction?

Also, help, __doc__ and dir do not return anything meaningful(to me
anyway) or helpful. There seem to be no exposed methods or properties.
e.g. I have a word document object:
wd = wordapp.Documents.Open('blah.dic')
But:>>> dir(wd)

['_ApplyTypes_', '_FlagAsMethod', '_LazyAddAttr_', '_NewEnum',
'_Release_', '__AttrToID__', '__LazyMap__', '__call__', '__cmp__',
'__doc__', '__getattr__', '__getitem__', '__init__', '__int__',
'__len__', '__module__', '__nonzero__', '__repr__', '__setattr__',
'__setitem__', '__str__', '_builtMethods_', '_enum_',
'_find_dispatch_type_', '_get_good_object_',
'_get_good_single_object_', '_lazydata_', '_make_method_',
'_mapCachedItems_', '_oleobj_', '_olerepr_', '_print_details_',
'_proc_', '_unicode_to_string_', '_username_', '_wrap_dispatch_']

And:

    The dynamic class used as a last resort.
    The purpose of this overriding of dynamic.CDispatch is to
perpetuate the policy
    of using the makepy generated wrapper Python class instead of
dynamic.CDispatch
    if/when possible.

Furthermore:>>> help(wd)

Help on instance of CDispatch in module win32com.client object:

class instance(object)
 |  instance(class[, dict])
 |
 |  Create an instance without calling its __init__() method.
 |  The class must be a classic class.
 |  If present, dict must be a dictionary or None.
 |
 |  Methods defined here:
 |
 |  __abs__(...)
 |      x.__abs__() <==> abs(x)

~ ~ snip ~ ~

|  __truediv__(...)
 |      x.__truediv__(y) <==> x/y
 |
 |  __xor__(...)
 |      x.__xor__(y) <==> x^y
 |
 |  next(...)
 |      x.next() -> the next value, or raise StopIteration
 |
 |
----------------------------------------------------------------------
 |  Data and other attributes defined here:
 |
 |  __new__ = <built-in method __new__ of type object at 0x1E1C74D0>
 |      T.__new__(S, ...) -> a new object with type S, a subtype of T

What gives?

Hmmm. The VB examples in the Word Object Reference give the best idea
of how to play with Word documents. No further help required on this
although I am still curious about why the python does not return the
"real" objects and methods for the COM object.
 
T

Tim Golden

Brendan said:
Hmmm. The VB examples in the Word Object Reference give the best idea
of how to play with Word documents. No further help required on this
although I am still curious about why the python does not return the
"real" objects and methods for the COM object.


Try doing it this way:

<code>
import win32com.client

word = win32com.client.gencache.EnsureDispatch ("Word.Application")

help (word)

doc = win32com.client.gencache.EnsureDispatch (word.Documents.Add ())

help (doc)

</code>


or just run the makepy util first.

TJG
 

Members online

No members online now.

Forum statistics

Threads
473,994
Messages
2,570,223
Members
46,813
Latest member
lawrwtwinkle111

Latest Threads

Top