views:

649

answers:

5

I am working on a project(in python) that needs formatted, editable output. Since the end-user isn't going to be technically proficient, the output needs to be in a word processor editable format. The formatting is complex(bullet points, paragraphs, bold face, etc), I'm wondering if there is a way to generate such a report using python. I feel like there should be a way to do this using word/ooffice templates and python, but I can't find anything advanced enough to get good formatting. Any suggestions?

+2  A: 

I know there is an odtwriter for docutils. You could generate your output as reStructuredText and feed it to odtwriter or look into what odtwriter is using on the backend to generate the ODT and use that.

(I'd probably go with generating rst output and then hacking odtwriter to output the stuff I want (and contribute the fixes back to the project), because that's probably a whole lot easier that trying to render your stuff to ODT directly.)

Aaron Maenpaa
+1: RST xxxxxxx15
S.Lott
A: 

I've used xlwt to create Excel documents using python, but I haven't needed to write word files yet. I've found this package, OOoPy, but I haven't used it.

Also you might want to try outputting html files and having the users open them in Word.

Adrian Mester
A: 

I think OpenOffice has some Python bindings - you should be able to write OO macros in Python.

But I would use HTML instead - Word and OO.org are rather good at editing it and you can write it from Python easily (although Word saves a lot of mess which could complicate parsing it by your Python app).

Roman Plášil
+2  A: 

" The formatting is complex(bullet points, paragraphs, bold face, etc), "

Use RST.

It's trivial to produce, since it's plain text.

It's trivial to edit, since it's plain text with a few extra characters to provide structural information.

It formats nicely using a bunch of tools.

S.Lott
+2  A: 

A little known, and slightly evil fact: If you create an HTML file, and stick a .doc extension on it, Word will open it as a Word document, and most users will be none the wiser.

Except maybe a very technical person will say, my this is a small Word file! :)

Ryan Ginstrom
And then if a user edits it and re-saves, what happens?
Craig McQueen
Then it becomes a normal Word file.
Ryan Ginstrom
that is very helpful - thanks Ryan
Plumo