473,387 Members | 1,705 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,387 software developers and data experts.

MS word document generator

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

Mar 15 '06 #1
13 5406
Raja Raman Sundararajan wrote:
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
Mar 15 '06 #2
Raja Raman Sundararajan wrote:
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

Mar 15 '06 #3
Hi Tim,
Thanks for your PyRTF suggestion. I am checking it out now
:-)
/R

Mar 15 '06 #4
On 2006-03-15, Raja Raman Sundararajan <ra*****@hotmail.com> wrote:
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.
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.


--
Grant Edwards grante Yow! ... I have read the
at INSTRUCTIONS...
visi.com
Mar 15 '06 #5
Hi guys,
Thanks for your note Grant.
I had a look at the pyRTF and it seems to be quite impressive :-)
I actually works for my needs except the below, concerning cells in a
table

For cells in a table, pyRTF does not support
1. ALIGN_RIGHT
2. Cell background

Do you guys have any idea of how to do this?

Thanks
/R

Mar 15 '06 #6
Hi!

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

It was good to remember it.

MCI
Mar 15 '06 #7
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

Mar 15 '06 #8
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

Mar 15 '06 #9
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
--
The problem with the world is stupidity. Not saying there should be a
capital punishment for stupidity, but why don't we just take the
safety labels off of everything and let the problem solve itself?
Frank Zappa
Mar 15 '06 #10
On 2006-03-15, Sybren Stuvel <sy*******@YOURthirdtower.com.imagination> wrote:
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.


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.

--
Grant Edwards grante Yow! .. I think I'd
at better go back to my DESK
visi.com and toy with a few common
MISAPPREHENSIONS...
Mar 16 '06 #11
Hi!

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

Michel Claveau
Mar 16 '06 #12
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

Mar 16 '06 #13
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.

:-)

Mar 23 '06 #14

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

4
by: Otis Hunter | last post by:
I have been given an Access Database which contains a table that has an OLE object field that contains a Word document. That table contains hundreds of records. I would like to find out how I can...
10
by: Noor | last post by:
Hi all, I need to well formatted ms word document through vb.net. All the data that will make the word document will come from the database. and formatted dynamically. Currently i have...
0
by: Michael | last post by:
Hi All, I have a general question. I'm in the process of designing a app that will allow user to enter data for Medical forms and print the corresponding word doc. I have about 100 forms I have to...
3
by: Adam Faulkner via DotNetMonster.com | last post by:
I want to create a method within a class that opens a Microsoft Word 2000 Document and has the facility to Create a new word document and then extract a Page that exists within the original Word...
1
by: Adam Faulkner via DotNetMonster.com | last post by:
I had a problem before extracting pages from an existing word document and then inserting the content into a new word document. The following code below works with Microsoft Word 2000 Function...
0
by: Miloann | last post by:
We are implementing an application that sends reminder emails to employees in other departments through intranet. The application comes with an email template in ASPX. Can I modify the codes to...
0
by: Niyazi | last post by:
Hi, I created application that store the data in SQL SERVER that reside on network. The client also use this application to access the resources provided with application. But is the client want...
2
by: allan.s.palmer | last post by:
Hello, I have an asp.net pop up that is generating a Word document real time and sending it to the user by sending the appropriate response headers. When it is run on our development environment...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.