如何使用C#读取功率点图像的超链接 [英] How to read the hyper-link of an image in power Point using c#
问题描述
我已经插入的图片用c#PowerPoint和已插入超链接,照片和工作perfectly.But现在我需要阅读这是我使用C#插入的图片的链接。
I have inserted an image to powerpoint using c# and have inserted a hyperlink to the picture and its working perfectly.But now i need to read the hyperlink of that picture which i have inserted using c#.
而我插入文本超链接到PowerPoint中使用C#,和我用下面的方法读取超链接从PowerPoint中回来了。
Whereas am inserting a text with hyperlink into powerpoint using c# ,and am reading the hyperlink back from the powerpoint by the below method.
for (int i = 0; i < presentation.Slides.Count; i++)
{
foreach (var item in presentation.Slides[i + 1].Shapes)
{
var shape = (PPT.Shape)item;
if (shape.HasTextFrame == MsoTriState.msoTrue)
{
if (shape.TextFrame.HasText == MsoTriState.msoTrue)
{
var textRange = shape.TextFrame.TextRange;
var text = textRange.Text;
string address=textRange.ActionSettings[PPT.PpMouseActivation.ppMouseClick].Hyperlink.Address;
}
}
}
}
在这里我得到的超级链接地址中的变量的地址后,同样我需要从我所使用C#插入PPT图像的超链接。
where am getting the hyperlink address in the variable address, likewise i need to get the hyperlink from the image which i have inserted into PPT using c#.
是否有可能。??
推荐答案
一个办法是通过形状在幻灯片上进行迭代,看看他们是否含有超链接。或创建它的时候,然后由指定ID找到它,你应该给你的照片的ID。
One option would be to iterate through Shapes on a Slide and see, whether they contain hyperlink. Or you should give your picture an id when creating it and then find it by the given id.
private void GetHyperlink()
{
Microsoft.Office.Interop.PowerPoint.Application objApp = new Microsoft.Office.Interop.PowerPoint.Application();
objApp.Visible = Microsoft.Office.Core.MsoTriState.msoTrue;
Presentations objPresSet = objApp.Presentations;
Presentation p = objPresSet.Open("C:\test.ppt");
Slide slide = p.Slides[1];
// or Slide slide = objApp.ActiveWindow.View.Slide;
for (int i = 1; i <= slide.Shapes.Count; i++)
{
//If the hyperlink address is filled then display it in MessageBox
if (slide.Shapes[i].ActionSettings[PpMouseActivation.ppMouseClick].Hyperlink.Address != null)
MessageBox.Show(slide.Shapes[i].ActionSettings[PpMouseActivation.ppMouseClick].Hyperlink.Address);
}
}
这code将显示在幻灯片1所有超链接。
此外,它会是有趣的,使用Open XML SDK用于此目的,而不是自动化。
This code will display all hyperlinks on slide 1. Also it would be interesting to use Open XML SDK for this purpose instead of automation.
有趣的链接:
HTTP://www.aspose。 COM /文档/显示/ slidesnet /查找+ A +形状+在+ A +滑动
我建议你先修改code,与这样的超链接创建映像:
I suggest you first modify the code that creates the image with hyperlink like this:
//Add a picture
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);
//Here you have various options how to distinguish your shape
pic.Name = "MyPic";
pic.AlternativeText = "Koala";
pic.Tags.Add("MyPic", "@http://www.google.com/");
//adding hyperlink, etc...
pic.ActionSettings[PpMouseActivation.ppMouseClick].Hyperlink.Address =@"http://www.google.com/"
然后,当你阅读文件,您可以使用标签或名称来区分的形状:
Then when you read the file you can use tags or name to distinguish shapes:
//tags check
if (slide.Shapes[i].Tags.Count > 0 && slide.Shapes[i].Tags["MyPic"]!=null && slide.Shapes[i].ActionSettings[PpMouseActivation.ppMouseClick].Hyperlink.Address != null)
MessageBox.Show(slide.Shapes[i].ActionSettings[PpMouseActivation.ppMouseClick].Hyperlink.Address);
//or
//name check
if (slide.Shapes[i].Name.Equals("MyPic", StringComparison.InvariantCultureIgnoreCase) && slide.Shapes[i].ActionSettings[PpMouseActivation.ppMouseClick].Hyperlink.Address != null)
MessageBox.Show(slide.Shapes[i].ActionSettings[PpMouseActivation.ppMouseClick].Hyperlink.Address);
这篇关于如何使用C#读取功率点图像的超链接的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!