I am working to automate report generation using python. In a word document, I need to update the Form Fields to complete the report generation.
On using win32.com.client.gencache.EnsureDispatch
api, I am not able to get the formFields from the word document.
Following is the script written:
I am getting following error:
raise AttributeError("'%s' object has no attribute '%s'" % (repr(self), attr))
AttributeError: '<win32com.gen_py.Microsoft Word 16.0 Object Library.FormFields instance at 0x2217380698888>' object has no attribute '__getitem__'
I tried to search for the help on how to get the FormFields present in the word document but could not find any proper documentation on the error that I am getting.
word = win32.gencache.EnsureDispatch('Word.Application')
word.Visible='False'
file = os.path.abspath(path)
d = word.Documents.Open(file)
d.FormFields[0].Result = reviewer
d.FormFields[0].Result should be a valid attribute.
on printing d
, it is got to know that the object does not contain any FormFields at-all.
['CLSID', '__doc__', '__getattr__', '__init__', '__module__', '__repr__', '__setattr__', '_dispobj_', 'coclass_interfaces', 'coclass_sources', 'default_interface', 'default_source']