简体   繁体   English

如何使用c#使用超级链接将图像从剪贴板插入或粘贴到Power Point

[英]how to insert or paste an image from clipboard to Power Point with hyper link Using c#

Am developing an ad-din for power Point , for that i need to insert a image from Local disk or need to paste the image from clipboard to power point using c#.But here i was able to do both the functions without adding hyper-link,But i need the hyper-link to be also added. 我正在为Power Point开发一个ad-din,为此我需要从本地磁盘插入图像或需要使用c#将剪贴板中的图像粘贴到Power Point。但是在这里我能够完成这两个功能而无需添加超链接,但我还需要添加超链接。

used to insert a picture to PPT: 用于将图片插入PPT:

 slide.Shapes.AddPicture(path, Microsoft.Office.Core.MsoTriState.msoFalse,
                      Microsoft.Office.Core.MsoTriState.msoTrue, shape.Left, shape.Top, shape.Width, shape.Height);

Used to paste a picture from clip Board: 用于从剪贴板粘贴图片:

slide.Shapes.Paste();

both the above process are working.but how to insert an image with hyper-link?Been struck here for past 2 days. 上面的两个过程都正常,但是如何插入带有超链接的图像呢?过去两天来这里罢了。

  PPT.Shape  shap1=   slide.Shapes.AddTextbox(Microsoft.Office.Core.MsoTextOrientation.msoTextOrientationHorizontal, 50,50,250,50);


                PPT.TextRange objTextRng;
                objTextRng = shap1.TextFrame.TextRange;
                objTextRng.Text = txt;

                objTextRng.ActionSettings[PPT.PpMouseActivation.ppMouseClick].Hyperlink.Address = @"http://google.com";

in the above mentioned way am inserting hyper-link to the text in PPT , Likewise i need to add hyper-link to am image in PPT. 以上述方式将超链接插入PPT中的文本,同样,我需要向PPT中的图像添加超链接。 Thanks 谢谢

I believe the code you are looking for is: 我相信您正在寻找的代码是:

pic.ActionSettings[PpMouseActivation.ppMouseClick].Hyperlink.Address = @"http://www.google.com/";

And the whole method that creates new presentation with Image with hyperlink is: 创建带有超链接的图像的新演示文稿的整个方法是:

using Microsoft.Office.Interop.PowerPoint;
...

    private void AddImageWithHyperlink()
    {
        Microsoft.Office.Interop.PowerPoint.Application objApp = new Microsoft.Office.Interop.PowerPoint.Application();
        objApp.Visible = Microsoft.Office.Core.MsoTriState.msoTrue;
        Presentations objPresSet = objApp.Presentations;
        Presentation objPres = objPresSet.Add(Microsoft.Office.Core.MsoTriState.msoTrue);            
        Slide slide =
            objPres.Slides.Add(
            objPres.Slides.Count + 1,
            PpSlideLayout.ppLayoutPictureWithCaption);

        // Shapes[2] is the image shape on this layout.
        Shape shape = slide.Shapes[2];

        Shape pic = slide.Shapes.AddPicture(@"C:\Users\Public\Pictures\Sample Pictures\koala.jpg",
        Microsoft.Office.Core.MsoTriState.msoFalse,
        Microsoft.Office.Core.MsoTriState.msoTrue,
        shape.Left, shape.Top, shape.Width, shape.Height);

        pic.ActionSettings[PpMouseActivation.ppMouseClick].Hyperlink.Address =@"http://www.google.com/";
    }

Also check your Microsoft.Office.Interop.PowerPoint.dll version, should be 14 or higher... 还要检查您的Microsoft.Office.Interop.PowerPoint.dll版本,应为14或更高版本。

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

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