whitespace in a word doc

Tim Golden mail at timgolden.me.uk
Thu Jul 15 03:59:30 EDT 2010


On 15/07/2010 08:45, Bruce wrote:
> I'm trying to create a word doc using win32com. 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.
>
> 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?

Couple of things which will help us to help you:

1) Consider what's going on *without* Python: if you take the exact
same text and spaces and type it into a Word document, does the same
thing happen? If so, then there is something of a gap in your understanding
of how Word arranges spaces, especially with proportional fonts.

2) If the text looks fine when you type it in but dodgy when programmed
in from Python, post the code here. If there's an issue with the way
your code is doing what its' doing, we need to see the code to work
that out. (Usually).

If you want things to line up in columns in Word, you probably want to
do one of two things (possibly both): use a fixed-width font, eg Courier 
New;
use Word tables. If you go the latter route, it can sometimes be easier to
generate the equivalent HTML and then ask Word to open it directly. Depends.


TJG



More information about the Python-list mailing list