Aligning the text in a given table cell via C#/Automation

  • Thread starter Thread starter some guy
  • Start date Start date
S

some guy

From what I can tell, I need to get a ShapeRange reference and call the
Align() method. I think my 2nd line of code is OK but I have no idea about
line 1. Any hints would be GREATLY appreciated.
1) PowerPoint11.ShapeRange theShapeRange =
theTable.Table.Cell(2,1).SomeMethod?
2) theShapeRange.Align(MsoAlignCmd.msoAlignLefts, MsoTriState.msoFalse);
 
some guy said:
From what I can tell, I need to get a ShapeRange reference and call the
Align() method. I think my 2nd line of code is OK but I have no idea
about line 1. Any hints would be GREATLY appreciated.
1) PowerPoint11.ShapeRange theShapeRange =
theTable.Table.Cell(2,1).SomeMethod?
2) theShapeRange.Align(MsoAlignCmd.msoAlignLefts, MsoTriState.msoFalse);
Not sure if this is considered a 'best practice' - but this does the trick
for me:

PowerPoint11.Shape theTable = pptSlide.Shapes.AddTable(3, 3, 150, 150, 480,
320);
..
..some other non-relevant stuff
..
theTable.Table.Cell(2,
1).Shape.TextFrame.TextRange.ParagraphFormat.Alignment =
PowerPoint11.PpParagraphAlignment.ppAlignLeft;
 
Not sure if this is considered a 'best practice' - but this does the trick
for me:

PowerPoint11.Shape theTable = pptSlide.Shapes.AddTable(3, 3, 150, 150, 480,
320);
..
..some other non-relevant stuff
..
theTable.Table.Cell(2,
1).Shape.TextFrame.TextRange.ParagraphFormat.Alignment =
PowerPoint11.PpParagraphAlignment.ppAlignLeft;

I guess "only way to get there" qualifies as being "best way to get there". <g>

It might be marginally faster if you defined your own ppAlignLeft constant = to
the same value as PowerPoint's ppAlignLeft but unless you're doing this many
times in a loop, it's unlikely you'd see the speed difference.
 
Back
Top