[python-win32] Converting HTML formatting to Microsoft Word

Tom tomforbes8 at hotmail.com
Tue Jun 14 01:20:26 CEST 2011


Hello,
I have a Javascript rich text editor (Specifically the Yahoo UI
libraries Simple Editor) which I have embedded within my web
application. This produces formatted HTML from the users input which
has to be placed within a Word document.
The number of formatting options is limited - Bold, italics,
underline, font size, font type, image insertion and lists. I thought
this would be rather simple to automate using words COM interface, but
I am having a lot of issues formatting the text using the COM
interface - my solution so far parses the HTML using BeautifulSoup and
rolls through each tag. If its a bold tag then it creates a range
object at the end of the current one, inserts the bold text and sets
the Bold attribute to True.

My issue is that this doesn't work and produces confusing results -
the text isn't formatted correctly and the Bold attribute is set to -1
(Which means a mix of both bold and non bold as far as I can tell).

Does anyone have any experience doing anything similar to this, or can
anyone give me a simpler way to do this?

~Tom


More information about the python-win32 mailing list