MS word document generator

  • Thread starter Raja Raman Sundararajan
  • Start date
R

Raja Raman Sundararajan

Hello guys,
Is there any nice library to generate word documents using Python.

As of today I am generating a HTML document and then open it with MS
Word.
But the problem is that I am not able to control the pages in the
document and as a result of it the output looks terrible.

I have been using reportlab's platypus to generate PDF documents.
Its a nice application which allows controlling segments of the pages
programatically.

I was wondering if there was any library as reportlab to generate word
documents.

Thanks,
/R
 
M

Max M

Raja said:
I was wondering if there was any library as reportlab to generate word
documents.

If you are on Windows, why dont you use word for it? You can call it
from Python.


--

hilsen/regards Max M, Denmark

http://www.mxm.dk/
IT's Mad Science

Phone: +45 66 11 84 94
Mobile: +45 29 93 42 96
 
T

Tim Churches

Raja said:
Hello guys,
Is there any nice library to generate word documents using Python.

As of today I am generating a HTML document and then open it with MS
Word.
But the problem is that I am not able to control the pages in the
document and as a result of it the output looks terrible.

I have been using reportlab's platypus to generate PDF documents.
Its a nice application which allows controlling segments of the pages
programatically.

I was wondering if there was any library as reportlab to generate word
documents.

How about PyRTF to generate Rich Text Format documents which MS-Word
will lap up? Thanks to the efforts of Simon Cusack (hi Simon).

See http://cheeseshop.python.org/pypi/PyRTF/0.45

Tim C
 
M

Méta-MCI

Hi!

PyRTF is old, but run OK. I use it, with some little modifs, for another
usage.

It was good to remember it.

MCI
 
M

Méta-MCI

Hi!

The next MS-Office come with a new format of document, based on XML+Zip.
But MS-Word can read, now, a XML file.

Perhaps you can use this way.

@-salutations

Michel Claveau
 
R

Raja Raman Sundararajan

Hi Tim,
Thanks for your PyRTF suggestion. I am checking it out now
:)
/R
 
G

Grant Edwards

Is there any nice library to generate word documents using Python.

I find the following works well for me:

f = open("file.doc")
f.write("Hello there.\n")
f.write("How are you?\n")
f.close()
As of today I am generating a HTML document and then open it
with MS Word. But the problem is that I am not able to control
the pages in the document and as a result of it the output
looks terrible.

If you want fancier formatting that available in my example
code, I'd look for a library to generate RTF. Something like
this perhaps (I haven't tried it yet):

http://pyrtf.sourceforge.net/

RTF is far more portable that whatever ".doc" format-du-jour
happens to be in vogue in Redmond.
 
R

Raja Raman Sundararajan

Hi Michel,
Well, Office 12 will have very many features. Thats true.
But my document needs to work in all versions of Office.
I hope that pyRtf generated file is fully rtf compatible. :)
But so far I think it is quite okay.


To answer my first question:
1. do an align right of contents inside a cell

Its not possible by speficying alignment in the Cell instance

However, if you really want this feature then create a Paragraph and
then set alignment=2 for the ParagraphPropertySet object
Snippet:
p = Paragraph( ss.ParagraphStyles.Normal, ParagraphPS(alignment=2)
)
p.append(<some text here>)
c1 = Cell(p)

I need to fiddle around with the RTF to see if I can implement coloring
of Cells

:)
/R
 
S

Sybren Stuvel

Raja Raman Sundararajan enlightened us with:
Well, Office 12 will have very many features. Thats true.
But my document needs to work in all versions of Office.
I hope that pyRtf generated file is fully rtf compatible. :)

Oh come on. Even Word files don't work in all versions of Office.

Sybren
 
G

Grant Edwards

Raja Raman Sundararajan enlightened us with:

Oh come on. Even Word files don't work in all versions of Office.

RTF is far more portable between versions office. At my
previous employer, all controlled documents that were generated
using office were archived in RTF format.
 
M

Méta-MCI

Hi!

Yes, I have an idea. But... I has no time, actually.
Perhaps in 2 or 3 weeks... Sorry.

Michel Claveau
 
P

paron

You might also consider OpenOffice, which writes to ODF. That way,
you're working to a standard. You can script OpenOffice in Python
(http://udk.openoffice.org/python/python-bridge.html) . OpenOffice can
save in .doc, and does a pretty good job of making a file that most MS
Word versions will render properly.

According to http://opendocumentfellowship.org/Devel/LibOpenDocument,
there is a Python API in development, but I don't know how far along
they are. ODF isn't too bad to hack, if you need to do that.

Ron
 
R

Raja Raman Sundararajan

Hi paron,
I am using PyRTF as of now and it seems to fit my need quite well
and it works like a charm :).
I have made a wrapper around it so that it will easier for me to switch
the backend for generating the word/RTF docs later.
May be, it will be openoffice :)
I appreciate your input. Thank you.

:)
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
474,169
Messages
2,570,919
Members
47,458
Latest member
Chris#

Latest Threads

Top