Jump to content
Wikibooks The Free Textbook Project

Python Programming/MS Word

From Wikibooks, open books for an open world

This is the current revision of this page, as edited by DannyS712 (discuss | contribs) at 06:52, 16 April 2020 (Update syntaxhighlight tags - remove use of deprecated <source> tags). The present address (URL) is a permanent link to this version.

Revision as of 06:52, 16 April 2020 by DannyS712 (discuss | contribs) (Update syntaxhighlight tags - remove use of deprecated <source> tags)
(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)

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:

importwin32com.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
[edit | edit source ]

AltStyle によって変換されたページ (->オリジナル) /