2014-07-21 177 views
0

我正在開發一個電源點的廣告,爲此我需要從本地磁盤插入圖像或需要將圖像從剪貼板粘貼到功能點使用C#。但在這裏我能夠做到這兩個功能,而無需添加超鏈接,但我需要超鏈接也被添加。如何從剪貼板插入或粘貼到超級鏈接Power Point使用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(); 

上述兩種過程中working.but 如何插入圖像與超鏈接?在過去兩天內被擊中。

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到我的形象。 感謝

回答

1

我相信你正在尋找的代碼是:

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

這與超鏈接的圖像創建新的演示文稿的整個方法是:

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 [email protected]"http://www.google.com/"; 
    } 

還要檢查你的Microsoft.Office .Interop.PowerPoint.dll版本,應該是14或更高...

+1

我有一些懷疑..可以請你指導我.. !! – Arshad

+0

真的首先檢查你的PIA版本(引用的Microsoft.Office.Interop.PowerPoint.dll)是什麼。使用最新的版本。我測試了這個代碼與PowerPoint 2013和PIA v14.0 –

+0

我相信你做錯了什麼,你設置ActionSettings不插入形狀(圖片),但在TextBox –