I'd like to create a Word document using Python, however, I want to re-use as much of my existing document-creation code as possible. I am currently using an XSLT to generate an HTML file that I programatically convert to a PDF file. However, my client is now requesting that the same document be made available in Word (.doc) format.
So far, I haven't had much luck finding any solutions to this problem. Is anyone aware of an open source library (or *gulp* a proprietary solution) that may help resolve this issue?
NOTE: All possible solutions must run on Linux. I believe this eliminates pywin32.
Open the target document in Microsoft Word and place the cursor where the source code will appear. Select Insert. In the Text group, select Object. In the Object dialog box, select the Create New tab.
A couple ways you can create Word documents using Python:
pywin32
). http://python.net/crew/pirx/spam7/ EDIT:
Since COM is out of the question, I suggest the following (inspired by @kcrumley's answer):
Using the UNO library to automate Open Office from python, open the HTML file in OOWriter, then save as .doc.
EDIT2:
There is now a pure Python python-docx project that looks nice (I have not used it).
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With