本文整理汇总了C#中OpenXmlPart.AddHyperlinkRelationship方法的典型用法代码示例。如果您正苦于以下问题:C# OpenXmlPart.AddHyperlinkRelationship方法的具体用法?C# OpenXmlPart.AddHyperlinkRelationship怎么用?C# OpenXmlPart.AddHyperlinkRelationship使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类OpenXmlPart
的用法示例。
在下文中一共展示了OpenXmlPart.AddHyperlinkRelationship方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: AddRelationships
private static void AddRelationships(OpenXmlPart oldPart, OpenXmlPart newPart, IEnumerable<XElement> newContent)
{
var relevantElements = newContent.DescendantsAndSelf()
.Where(d => RelationshipMarkup.ContainsKey(d.Name) &&
d.Attributes().Any(a => RelationshipMarkup[d.Name].Contains(a.Name)))
.ToList();
foreach (var e in relevantElements)
{
if (e.Name == W.hyperlink)
{
string relId = (string)e.Attribute(R.id);
if (string.IsNullOrEmpty(relId))
continue;
var tempHyperlink = newPart.HyperlinkRelationships.FirstOrDefault(h => h.Id == relId);
if (tempHyperlink != null)
continue;
Guid g = Guid.NewGuid();
string newRid = "R" + g.ToString().Replace("-", "");
var oldHyperlink = oldPart.HyperlinkRelationships.FirstOrDefault(h => h.Id == relId);
if (oldHyperlink == null)
continue;
//throw new DocumentBuilderInternalException("Internal Error 0002");
newPart.AddHyperlinkRelationship(oldHyperlink.Uri, oldHyperlink.IsExternal, newRid);
UpdateContent(newContent, e.Name, relId, newRid);
}
if (e.Name == W.attachedTemplate || e.Name == W.saveThroughXslt)
{
string relId = (string)e.Attribute(R.id);
if (string.IsNullOrEmpty(relId))
continue;
var tempExternalRelationship = newPart.ExternalRelationships.FirstOrDefault(h => h.Id == relId);
if (tempExternalRelationship != null)
continue;
Guid g = Guid.NewGuid();
string newRid = "R" + g.ToString().Replace("-", "");
var oldRel = oldPart.ExternalRelationships.FirstOrDefault(h => h.Id == relId);
if (oldRel == null)
throw new DocumentBuilderInternalException("Source {0} is invalid document - hyperlink contains invalid references");
newPart.AddExternalRelationship(oldRel.RelationshipType, oldRel.Uri, newRid);
UpdateContent(newContent, e.Name, relId, newRid);
}
if (e.Name == A.hlinkClick)
{
string relId = (string)e.Attribute(R.id);
if (string.IsNullOrEmpty(relId))
continue;
var tempHyperlink = newPart.HyperlinkRelationships.FirstOrDefault(h => h.Id == relId);
if (tempHyperlink != null)
continue;
Guid g = Guid.NewGuid();
string newRid = "R" + g.ToString().Replace("-", "");
var oldHyperlink = oldPart.HyperlinkRelationships.FirstOrDefault(h => h.Id == relId);
if (oldHyperlink == null)
continue;
newPart.AddHyperlinkRelationship(oldHyperlink.Uri, oldHyperlink.IsExternal, newRid);
UpdateContent(newContent, e.Name, relId, newRid);
}
if (e.Name == VML.imagedata)
{
string relId = (string)e.Attribute(R.href);
if (string.IsNullOrEmpty(relId))
continue;
var tempExternalRelationship = newPart.ExternalRelationships.FirstOrDefault(h => h.Id == relId);
if (tempExternalRelationship != null)
continue;
Guid g = Guid.NewGuid();
string newRid = "R" + g.ToString().Replace("-", "");
var oldRel = oldPart.ExternalRelationships.FirstOrDefault(h => h.Id == relId);
if (oldRel == null)
throw new DocumentBuilderInternalException("Internal Error 0006");
newPart.AddExternalRelationship(oldRel.RelationshipType, oldRel.Uri, newRid);
UpdateContent(newContent, e.Name, relId, newRid);
}
if (e.Name == A.blip)
{
string relId = (string)e.Attribute(R.link);
if (string.IsNullOrEmpty(relId))
continue;
var tempExternalRelationship = newPart.ExternalRelationships.FirstOrDefault(h => h.Id == relId);
if (tempExternalRelationship != null)
continue;
Guid g = Guid.NewGuid();
string newRid = "R" + g.ToString().Replace("-", "");
var oldRel = oldPart.ExternalRelationships.FirstOrDefault(h => h.Id == relId);
if (oldRel == null)
continue;
newPart.AddExternalRelationship(oldRel.RelationshipType, oldRel.Uri, newRid);
UpdateContent(newContent, e.Name, relId, newRid);
}
}
}