How to add an hyperlink to a shape in a presentation using OpenXml SDK

∥☆過路亽.° 提交于 2019-12-12 02:13:21

问题


I am developing with C# application to create a PowerPoint presentation.

I am using the OpenXML SDK 2.0 and MS Office PP 2007.

I am able to clone my slides from my template and add a new shape on it.

But now i want to add a Hyperlink to my shape.

How can i do this?

I found this: tutorial but i need to add those hyperlinks at runtime.

I already tried this.

SlidePart currentSlidePart = CloneSlidePart(presentationPart, slidePart);
Slide s = currentSlidePart.Slide;
currentSlidePart.AddHyperlinkRelationship(new System.Uri("myuri", System.UriKind.Absolute), true, "rId2");

Then i called the method to create the shape:

s.CommonSlideData.ShapeTree.Append(generateTextShape("some content", shape));

And this is the method:

 public static Shape generateTextShape(String input, ShapePosition shapePosition)
 {
            Shape shape1 = new Shape();
...
            D.HyperlinkOnClick hyperlinkOnClick1 = new D.HyperlinkOnClick() { Id = "rId2" };
            nonVisualDrawingProperties1.Append(hyperlinkOnClick1);
...
    return shape1;
}

Right now, nothing happens.. What i am doing wrong, any suggestions?

(The class ShapePosition is just for x,y,width,height of a shape)

Best regards!


回答1:


You said "nothing happens", so I'm not going to assume. Please try a few of these ideas:

1) Hyperlinks show in slide show mode. Put the presentation into slide show mode (Hit F5) - then click on the shape.

2) Did you append your nonVisualDrawingProperties1 to your shape1? To tell, right click on the shape in PP2007 and select hyperlink... see if your URL is there. If it is not there, then you need to make sure nonVisualDrawingProperties1 gets added to your shape1 in generateShapeText method.

3) if the URL is there, but it is not working, perhaps you have your relationship Ids incorrect?? In PP2007 with that same file, create a new simple shape, add a new hyperlink, save it with a new filename and compare the 2 files with the productivity tool. You should see the new hyperlink and relationship that PP2007 generated.

You posted partial code in generateShapeText. If you could put the complete code, that might help us troubleshoot this with you. -Cheers.



来源:https://stackoverflow.com/questions/19681368/how-to-add-an-hyperlink-to-a-shape-in-a-presentation-using-openxml-sdk

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!