[python-win32] read word contents including images and font format

Anthony Mpofu anthony.mpofu at gmail.com
Wed Oct 5 15:53:15 CEST 2011


Hi All

I want to read contents from a word document (source) and insert the
contents to the (destination) word document.
I have used the following code:
# Read content from source
word = win32.gencache.EnsureDispatch('Word.Application')
doc = word.Documents.Open("source.doc")
data = word.Documents[0].Content

# Insert data read from source to destination document
dest_doc = word.Documents.Open("destination.doc")
startAt = dest_doc.Range(4,4)
startAt.InsertBefore(data)
dest_doc.SaveAs( "destination.doc" )

The above solution only copies the text content from the source document.
The read contents loses the original formating (font size, font type)
The read contents fails to load images from the document.

Is there a method that will allow reading word content with the original
formatting as well as images.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/python-win32/attachments/20111005/f1c7bf88/attachment.html>


More information about the python-win32 mailing list