简体   繁体   中英

Inserting pictures using interop (C#) into powerpoint

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: http://i.imgur.com/Ia2MVbk.png

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

Thank you.

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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM