How to write RTF from Python?
Bengt Richter
bokr at oz.net
Mon Apr 28 16:37:15 EDT 2003
On Mon, 28 Apr 2003 21:00:31 +0200, Irmen de Jong <irmen at -NOSPAM-REMOVETHIS-xs4all.nl> wrote:
>Sorry if this has already been mentioned or not appropriate
>but I'm hopping late into this thread and I missed the
>original messages...
>
>What we did quite successfully was typing a letter in Word, with special
>placeholders such as "%%%DATE%%%", "%%%AGE%%%" on the locations where
>you want your data items to appear.
>Save this as RTF.
>Load it as a 'template' in your program and replace the
>placeholders with the actual data values. Presto.
>
I suggested using (to translate your example) %(DATE)s %(AGE)s
in the locations, so you can use a dict (or something with a __getitem__ method)
to do template % aDict where aDict might be {'DATE':'2003-04-28', 'AGE':29} or whatever.
Also, you are likely to get less cruft in the .rtf if you use wordpad (write.exe) instead
of word, I think. See working example with code prev post.
Regards,
Bengt Richter
More information about the Python-list
mailing list