0

At end of my program, I am generating word file then converting this file to .pdf file format as the following:

wdFormatPDF = 17
word = comtypes.client.CreateObject('Word.Application')
doc = word.Documents.Open(resultfile)
doc.SaveAs(resultfilepdf, FileFormat=wdFormatPDF)
doc.Close()
word.Quit()

The program run properly but when I converting the

.py to .exe using pyinstaller –onefile option I get the following error when executing the .exe file.

Traceback (most recent call last):
  File "C:\python\tub\test\hc.py", line 344, in <module>
    word = comtypes.client.CreateObject('Word.Application')
  File "C:\Users\LT440\Anaconda2\lib\site-packages\comtypes\client\__init__.py", line 250, in CreateObject
return _manage(obj, clsid, interface=interface)
  File "C:\Users\LT440\Anaconda2\lib\site-packages\comtypes\client\__init__.py", line 188, in _manage
obj = GetBestInterface(obj)
  File "C:\Users\LT440\Anaconda2\lib\site-packages\comtypes\client\__init__.py", line 112, in GetBestInterface
interface = getattr(mod, itf_name)
AttributeError: 'module' object has no attribute '_Application'
[4112] Failed to execute script hc

Please advice.

a3abdelhafez
  • 31
  • 1
  • 1
  • 9
  • so what is the ```Word.Application``` object ? – py_dude Feb 26 '18 at 12:27
  • Regarding comtypes.client module __ini__.py file 'progid' may be a string like "Excel.Application", you can find more information as the following [link](https://github.com/enthought/comtypes/blob/master/comtypes/client/__init__.py) – a3abdelhafez Feb 27 '18 at 11:29
  • I experienced the same problem while converting my .doc files to pdf. Then I used win32com which worked fine (as described [here](https://stackoverflow.com/questions/16056793/python-win32com-client-dispatch-looping-through-word-documents-and-export-to-pdf)). – New2coding May 17 '18 at 09:17

1 Answers1

1

I have same。I solved it Clear Gen's cache! I am deleting all the caches in this directory. The conversion is normal! ..\Python3.6\Lib\site-packages\comtypes\gen

wei xu
  • 11
  • 1