Word Table Cell Text Formatting

E

Evan Stone

Hello,

I'm dynamically building a Table in Word (via automation in C#), and I need
to be able to set the horizontal alignment of the text (just right or left
for now - I'm not worrying about center), and here's how I'm (trying) to do
it:

//-----------------------------
Word.Cell currentCell =
wordTable.Cell(wordTable.Rows.Count, i);

currentCell.Range.Text = textValueToInsert;

Word.Paragraph currentParagraph =
currentCell.Range.Paragraphs.Item(1);

currentParagraph.Alignment = GetDetailTableFieldAlignment(fieldName);
//-----------------------------

(FYI, GetDetailTableFieldAlignment() is a method that returns
wdAlignParagraphRight or wdAlignParagraphLeft, depending on certain criteria
in a data table that I interrogate. The interrogation process is working
properly and is returning the appropriate values.)

What I'm finding is that if wdAlignParagraphLeft is returned, it seems to
format OK. Howefver, if wdAlignParagraphRight is returned, the text that is
inserted in the second line gets deleted when the alignment is applied in
the fourth line.

Perhaps I'm doing it incorrectly -- I get the feeling I'm missing an
important part to the puzzle, like perhaps I'm using the wrong object (i.e.
Paragraph) or something along those lines. If so, I'd like to know how to
get it to work properly, and if anyone has any suggestions I'd really
appreciate it!

Thanks in advance...

evan stone | software engineer
 
E

Evan Stone

Is it possible that the values are merely hidden? It seems that I can see
the values being inserted (flashing) very quickly...

[author launches notepad and copies table to it from Word]

yep. that's what's happening. evidently the right-alignment is set in such a
way that the values end up invisible -- and in examining the table, it looks
like the columns have a right margin setting that extends into the
neigboring cell, so the value is hidden when the cell is set to right
justification.

grrr.

OK. So how do I control the sizing of the margins within a table??? Can
someone provide some advice on that topic? :)

thanks in advance (again)!

evan stone | software engineer
 
C

Cindy M -WordMVP-

Hi Evan,
What I'm finding is that if wdAlignParagraphLeft is returned, it seems to
format OK. Howefver, if wdAlignParagraphRight is returned, the text that is
inserted in the second line gets deleted when the alignment is applied in
the fourth line.

Perhaps I'm doing it incorrectly -- I get the feeling I'm missing an
important part to the puzzle, like perhaps I'm using the wrong object (i.e.
Paragraph) or something along those lines.
The basic approach sounds OK...

Have you attempted applying the formatting manually, to see if the same thing
happens? My first inclination would be to check a couple of things in the
current cell formatting
- presence of TAB stops, espeically decimal tab stops
- paragraph right alignment for the cell (if it goes beyond the cell
boundary)

The horizontal ruler is the tool you need to check for these things,
visually. Tab stops are heavy black "L" or upside down "T" shaped things. The
right alignment a pentagon (almost a triangle). If these aren't completely
with in a cell's boundary, changing paragraph alignment can have really odd
effects. For example, the text can disappear because it's beyond the right
margin of the cell.

If you need to pursue this further, it's important to distinguish in Word
between:
- paragraphs (ENTER was pressed = /r = carriage return)
- new line (Shift+Enter = /n = Chr(11))
- line generated by word wrap, because it hit the end of the available
space (no character involved)

applying the paragraph format to the fourth line will have an effect on the
second line if that is not in a separate paragraph. Otherwise, it really
should not.

From the look of your code, all four lines must be one paragraph, because
you're addressing Item(1) for the cell...

Cindy Meister
INTER-Solutions, Switzerland
http://homepage.swissonline.ch/cindymeister (last update Jun 8 2004)
http://www.word.mvps.org

This reply is posted in the Newsgroup; please post any follow question or
reply in the newsgroup and not by e-mail :)
 
C

Cindy M -WordMVP-

Hi Evan,
Is it possible that the values are merely hidden? It seems that I can see
the values being inserted (flashing) very quickly...

[author launches notepad and copies table to it from Word]

yep. that's what's happening. evidently the right-alignment is set in such a
way that the values end up invisible -- and in examining the table, it looks
like the columns have a right margin setting that extends into the
neigboring cell, so the value is hidden when the cell is set to right
justification.

grrr.

OK. So how do I control the sizing of the margins within a table??? Can
someone provide some advice on that topic? :)
OK, I only saw this after replying to your original message... Glad to see I
was on the right track :) Try the RightInden property.

Note that generally, Word won't do this by itself. If the column width is
altered, the right indent will usually go with it.

Cindy Meister
INTER-Solutions, Switzerland
http://homepage.swissonline.ch/cindymeister (last update Jun 8 2004)
http://www.word.mvps.org

This reply is posted in the Newsgroup; please post any follow question or
reply in the newsgroup and not by e-mail :)
 
E

Evan Stone

Hello Cindy,
OK, I only saw this after replying to your original message... Glad to see I
was on the right track :) Try the RightInden property.

Yes. Your other reply hit it spot on with the right tab stop being in the
next cell.

So my question is... how do I adjust it? I'll research the RightIndent
property as you suggest and see if I can get that to work easily...

....another method that I considered after all this (but I don't know if it's
possible) is to create the table in HTML and then paste it into the current
insertion point location. Does this make sense? Is it possible, or should I
just go ahead and work with the right indentation/tab stop settings?

thanks!

evan stone | software engineer
 
E

Evan Stone

- presence of TAB stops, espeically decimal tab stops

is it possible to remove them?
- paragraph right alignment for the cell (if it goes beyond the cell
boundary)

this looks like a candidate as well... how do i adjust them?

thanks!

-evan
 
C

Cindy M -WordMVP-

Hi Evan,

Have you made any progress on this?
Yes. Your other reply hit it spot on with the right tab stop being in the
next cell.

So my question is... how do I adjust it? I'll research the RightIndent
property as you suggest and see if I can get that to work easily...
Is it a tabstop, or is it the indent? The tabstops collection (of a paragraph)
has a ClearAll method...
....another method that I considered after all this (but I don't know if it's
possible) is to create the table in HTML and then paste it into the current
insertion point location. Does this make sense? Is it possible, or should I
just go ahead and work with the right indentation/tab stop settings?
Can you identify where these are coming from? Before I can answer "what would
help", I have to understand where the problem is coming from. On its own, Word
won't do this. Something has to have interfered with how the table is being
generated.

If it is a problem with Tab stops, this could stem from the formatting applied
to the paragraph from which the Table is being generated, for example.

Cindy Meister
INTER-Solutions, Switzerland
http://homepage.swissonline.ch/cindymeister (last update Jun 8 2004)
http://www.word.mvps.org

This reply is posted in the Newsgroup; please post any follow question or reply
in the newsgroup and not by e-mail :)
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top