Inserting pictures using interop (C#) into powerpoint

1.2k views Asked by At

can someone help me out? I'm trying to insert pictures into powerpoint using this code:

PPT.Shape sheetShape = slides[slideIndex].Shapes[shapeName];

...

slides[slideIndex].Shapes.AddPicture(fileName, MsoTriState.msoFalse, MsoTriState.msoTrue, sheetShape.Left, sheetShape.Top, sheetShape.Height, sheetShape.Width);

my problem is, that it shifts the inserted picture like: https://i.stack.imgur.com/3thlS.png

So both have the same position but not really. What am I doing wrong?

Thank you.

1

There are 1 answers

0
RedDot On

So because there is still no answer, I have to answer myself.

The problem with the charts I wanted to insert was, that they got rotated before (export from excel as image, then rotate) but powerpoint act like they are not rotated, so they have the wrong size and positiion. But then I thought, there must be a possibility to rotate them in powerpoint, not before. And thats it. So I solved my problem with not exporting the charts from excel, but c&p them directly from excel and then rotate them in powerpoint.

Thats how it looks for me now:

            chart.CopyPicture();
            PPT.ShapeRange sr = slides[slideIndex].Shapes.PasteSpecial();
            sr.Rotation = 90;               
            sr.Left = sheetShape.Left+30;
            sr.Top = sheetShape.Top;                
            sr.Width = sheetShape.Width;
            sr.Height = sheetShape.Height;

            sheetShape.Delete();

Hope it helps if someone else got the problem.