whitespace in a word doc
Grant Edwards
invalid at invalid.invalid
Thu Jul 15 10:10:40 EDT 2010
On 2010-07-15, Bruce <epost2 at gmail.com> wrote:
> I'm trying to create a word doc using win32com.
Unfortunately the phrase "word doc" is meaningless.
Exactly what format file are you trying to generate? For example: Word97 "doc" or the
new "docx" format?
> I don't get the same whitespace as when printing the same stuff in
> the dos window. At the terminal I manage to line up the second column
> like
>
> apples 5
> pears 7
>
> I do this by adding whitespace characters to the strings in the first
> column so that their length is equal to that of the longest string in
> the first column.
Are you just generating an ASCII text file and then opening it in
word?
> I print the excact same string to word. but in the word doc somehting
> happens that messes things up like this :
>
> apples 5
> pears 7
>
> Needless to say, this is extremely frustrating. But why does it
> happen, and how can I align the column in word?
Why? Because word is using a viable-spaced font and the "dos window"
uses a fixed-width font.
If you want any control over the appearance of the document, you'll
have to either force word to open the file in a fixed-width font, or
you'll have to generate a file that contains formatting information.
What you appear to want is a table.
Generating RTF has worked well for me in the past:
http://code.google.com/p/pyrtf-ng/
http://pyrtf.sourceforge.net/
An enahanced version of pyRTF that supports EMF graphics and scaling
of graphics is available here:
http://www.panix.com/~grante/files/python/PyRTF-0.46.tar.gz
If you want to generate graphics, this might be worth a look
http://pyemf.sourceforge.net/
You might also be able to generate HTML and then open that file using
Word.
--
Grant Edwards grant.b.edwards Yow! The Osmonds! You are
at all Osmonds!! Throwing up
gmail.com on a freeway at dawn!!!
More information about the Python-list
mailing list