411 REFERENCE · Wikibooks
Python Programming/MS Word
Reference material by Wikibooks contributors. This retains its source identity and is not 411 news reporting.
Microsoft Word documents of the .docx format can be created or changed using python-docx 3rd party module.
The .doc format can be worked with on Windows using PyWin32 via COM interface, provided Word is installed. An example:
import win32com.client
wordapp = win32com.client.gencache.EnsureDispatch("Word.Application")
# wordapp.Visible = False
worddoc = wordapp.Documents.Open(r"C:\MyFile.doc")
wdFormatHTML = 8
worddoc.SaveAs(r"C:\MyFile.html", FileFormat=wdFormatHTML)
worddoc.ActiveWindow.Close()
# wordapp.Application.Quit(-1) - No need to quit; Word quits when its last window is closed
External links
python-docx, pypi.python.org
python-docx, readthedocs.io