1

I got the next situation. Got some variables:

        PowerPoint.Application objApp;
        Microsoft.Office.Interop.PowerPoint.Shape oShape;
        PowerPoint.Presentations objPresSet;
        PowerPoint._Presentation objPres;
        PowerPoint.Slides objSlides;
        PowerPoint._Slide objSlide;
        Microsoft.Office.Interop.PowerPoint.Shape oShape;

I'm creating a PowerPoint 2010 slide presentation:

        objApp = new PowerPoint.Application();
        objApp.Visible = MsoTriState.msoTrue;
        objPresSet = objApp.Presentations;
        objPres = objPresSet.Open(strTemplate, MsoTriState.msoFalse, MsoTriState.msoTrue, MsoTriState.msoTrue);
        objSlides = objPres.Slides;

Here I'm creating a slide:

        objSlide = objSlides.Add(2, PowerPoint.PpSlideLayout.ppLayoutTitleOnly);

For the next step I add the table to slide:

        int rows = 4;
        int cells = 10;
        oShape = objSlide.Shapes.AddTable(rows, cells, 10, 10, 400, 450);

And I don't have any problems with text adding to a specific cell:

        oShape.Table.Cell(1, 1).Shape.TextFrame.TextRange.Text = "Dummy Text";

But, the cell does not want to stretch. I tried to modify TextFrame with AutoSize property:

        oShape.Table.Cell(1, 1).Shape.TextFrame.AutoSize = MsoAutoSize.msoAutoSizeTextToFitShape;

And here I'm getting the "ArgumentException":

The specified value is out of range.

Any thoughts why it's happening? If no, are there another way to stretch table cell?

MCv
  • 118
  • 1
  • 10
  • 1
    To change the size of a table cell, you change the size of the shape that it represents: oShape.Table.Cell(1, 1).Shape.Width=xxx and so on – Steve Rindsberg Mar 04 '15 at 15:34
  • Hey Steve. I tried. NotImplementedException was unhandlend. – MCv Mar 04 '15 at 16:27
  • 1
    Sorry, my bad. You can't change the height/width of individual cells, but you can change the width of columns/height of rows: oShape.Table.Columns(2).Width = 123 – Steve Rindsberg Mar 05 '15 at 01:14
  • Hi Steve. Thats almost works. Here is the correct version: oShape.Table.Columns._Index(2).Width = 123; – MCv Mar 05 '15 at 09:18
  • 1
    I guess that Columns._Index(2) is a .NET difference from VBA. Glad to know you've got it sorted. – Steve Rindsberg Mar 05 '15 at 16:04

1 Answers1

2

So, thanks to Steve Rindsberg solution would be:

oShape.Table.Columns._Index(2).Width = 12;

Thats change size of columns in the table pretty well.

MCv
  • 118
  • 1
  • 10