正在为power Point开发一个ad-din,因为我需要从本地磁盘插入一个图像,或者需要使用c#将图像从剪贴板粘贴到电源点。但是在这里我能够完成这两个功能而不添加超链接,但我还需要添加超链接。
用于将图片插入PPT:
slide.Shapes.AddPicture(path, Microsoft.Office.Core.MsoTriState.msoFalse,
Microsoft.Office.Core.MsoTriState.msoTrue, shape.Left, shape.Top, shape.Width, shape.Height);
用于粘贴剪贴板中的图片:
slide.Shapes.Paste();
上述过程都在起作用。但是 如何使用超链接插入图像?过去2天来到这里。
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";
以上面提到的方式在PPT中插入超链接到文本,同样我需要在PPT中添加超链接到am图像。 感谢
答案 0 :(得分:1)
我相信你要找的代码是:
pic.ActionSettings[PpMouseActivation.ppMouseClick].Hyperlink.Address = @"http://www.google.com/";
使用带超链接的Image创建新演示文稿的整个方法是:
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/";
}
另请检查您的Microsoft.Office.Interop.PowerPoint.dll版本,应该是14或更高...