Evan Stone
02-08-2006, 10:08 PM
Hi,
I was wondering if there a convenient way to select a table in word, and
then tell it to right-justify all columns that contain numeric data (a la
Excel). Is this a feature that's available in Word (2000+) via automation?
I'm assuming that it isn't, but I figured I'd ask before I put a lot of work
into doing it manually if there was a way to do it automatically.
Thanks!
evan k. stone | software engineer
----------------------------------------
santa rosa, ca, usa
Evan Stone
02-09-2006, 12:04 AM
Well... I decided to go the "inconvenient" route, and it seems to work okay.
I just basically rip through the columns in the table, select them,
determine what alignment they require (based on a field value in a dataset),
and then set each column accordingly.
There's usually just a handful of columns, so it's not a real lengthy
process:
// -------- begin code snippet (C#) --------
private void AlignWordTableColumns(
Word.Table wordTable,
DataSet ds,
MyDataField [] fieldList)
{
int colCount = fieldList.Length;
for (int i=1;i<=(colCount);i++)
{
// select the next column
wordTable.Columns.Item(i).Select();
// get the alignment setting for this column...
wordApplication.Selection.ParagraphFormat.Alignment =
GetDetailTableFieldAlignment(ds, fieldList[i-1].name);
// ye olde alignment funkfix. some things never change...
wordApplication.Selection.ParagraphFormat.RightIndent
= wordApplication.InchesToPoints(0.01F);
// Note: "VBA.False" is just a constant defined in a class
// elsewhere that I use to assist in C# automation
// coding. It's not a native C#/.NET/COM Interop thing.
wordApplication.Selection.ParagraphFormat.SpaceAfterAuto
= (int)VBA.False;
wordApplication.Selection.ParagraphFormat.SpaceBeforeAuto
= (int)VBA.False;
}
}
// -------- end code snippet (C#) --------
Cindy M -WordMVP-
02-10-2006, 10:58 AM
Hi Evan,
> Well... I decided to go the "inconvenient" route, and it seems to work okay.
>
> I just basically rip through the columns in the table, select them,
> determine what alignment they require (based on a field value in a dataset),
> and then set each column accordingly.
>
this really is the most efficient manner :-)
Cindy Meister