3

I have have to generate a 2003 compatible doc file from python without using external program like OpenOffice or embedded language like java using Jasper, but I have not found a way to do it. Creating a docx is quite simple and not suppose a problem, but the doc file is another history. As an alternative solution I tried to generate a rtf file, but the unicode incompatibility (there is a library out there solving this) and the lack of features don't allow me to go further and meet my needs. Any advice or solution? Thanks in advance!

1
  • 2
    2003 was 9 years ago. It's time for people to accept docx format. MS even makes an add-on available for versions of office that don't support it originally. Commented Apr 12, 2012 at 9:20

3 Answers 3

4

A google for python generate word document lead to a lot of good results. It seems that either py docx or win32com.client are useful libraries.

To read docx files with Word 2003 you have to install a plugin.

Sign up to request clarification or add additional context in comments.

5 Comments

py docx generates docx files, which are not (direct) compatible with word 2003.
You can also read docx files in Word 2003, I added a link in the answer.
The project is multiplatform, it has to generate the doc file from linux or windows, so pywin32 is not an option. It seems that is not a proper library to create doc files... Plugin installation seems the best option... sigh...
I think installing the plugin is a good solution. This will enable all of your users to open docx files, also the ones they get from people other than you. Alternatively, you could work with the Open Document format, and install the plugin for that in MS Office....
Ok thanks, seems clients are still asking for futile things... I will use Latex in a future project ;)
1

Because it's a binary format you have few options. JODReports or Docmosis might be both sit over OpenOffice so can generate real doc-format files. You should be able to run either from Python and optionally bridging into Java if that improves your performance.

1 Comment

That was the best solution. For instance, I ended talking to our client to explain .docx was a better solution. He even installed IE8 and stopped using IE7... TT
0

You could generate HTML first, then automatize pandoc to convert it into an ODT. Then, using the PyUNO bridge, convert it to a Doc. It's a pretty long chain but I did not figure out a better way of doing it. Also have a look at http://wiki.services.openoffice.org/wiki/Python.

The specification of .doc files is, in my opinion, quite a mess and won't be easy to generate it directly with python. Although there have been some attempts of python libs for writing doc files, they are in very early stage and might not serve you...

1 Comment

In the project I can't use pyuno/openoffice, the file must be generated from python code. I had implemented this solution with great results, but the need of openoffice installed on the system is not allowed... :(

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.