简体   繁体   English

使用互操作(C#)将图片插入Powerpoint

[英]Inserting pictures using interop (C#) into powerpoint

can someone help me out? 有人可以帮我吗? I'm trying to insert pictures into powerpoint using this code: 我正在尝试使用此代码将图片插入PowerPoint中:

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 我的问题是,它会像这样移动插入的图片: 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. 我想插入的图表的问题是,它们在旋转之前(从excel导出为图像,然后旋转),但是powerpoint的行为就像它们没有旋转一样,因此它们的尺寸和位置都错误。 But then I thought, there must be a possibility to rotate them in powerpoint, not before. 但是后来我想,一定有可能在Powerpoint中旋转它们,而不是以前。 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. 因此,我解决了我的问题,而不是从excel中导出图表,而是直接从excel中进行操作,然后在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. 希望如果有人遇到问题会有所帮助。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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