Inserting HTML and Other Formats
Word can import and export HTML. The following line inserts an entire file into the current document:
>>> wordSelection.InsertFile(MYDIR + '\\tutorial.html') >>>
Furthermore, some experiments revealed that you don’t even need a full HTML document, just tagged text saved with the extension HTML.
So if you want an easy way to pump large amounts of text into a Word
document, generate the HTML and insert it. Python has an excellent
package, HTMLgen
, for
generating sophisticated markup from code. Word can import HTML
tables with reasonable success, and all of the standard HTML styles
are marked as styles in Word.
These days there is a need to produce both printed and online versions of documents. If you write code to generate the HTML, and then import it into a smart Word template with the right corporate header and footer, you have a complete solution.
Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.
Read now
Unlock full access