本文整理汇总了C#中OpenXmlPart.GetExternalRelationship方法的典型用法代码示例。如果您正苦于以下问题:C# OpenXmlPart.GetExternalRelationship方法的具体用法?C# OpenXmlPart.GetExternalRelationship怎么用?C# OpenXmlPart.GetExternalRelationship使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类OpenXmlPart
的用法示例。
在下文中一共展示了OpenXmlPart.GetExternalRelationship方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: CopyRelatedPartsForContentParts
private static void CopyRelatedPartsForContentParts(OpenXmlPart oldContentPart, OpenXmlPart newContentPart,
IEnumerable<XElement> newContent, List<ImageData> images)
{
var relevantElements = newContent.DescendantsAndSelf()
.Where(d => d.Name == VML.imagedata || d.Name == VML.fill || d.Name == VML.stroke || d.Name == A.blip)
.ToList();
foreach (XElement imageReference in relevantElements)
{
CopyRelatedImage(oldContentPart, newContentPart, imageReference, R.embed, images);
CopyRelatedImage(oldContentPart, newContentPart, imageReference, R.pict, images);
CopyRelatedImage(oldContentPart, newContentPart, imageReference, R.id, images);
}
foreach (XElement diagramReference in newContent.DescendantsAndSelf().Where(d => d.Name == DGM.relIds || d.Name == A.relIds))
{
// dm attribute
string relId = diagramReference.Attribute(R.dm).Value;
try
{
OpenXmlPart tempPart = newContentPart.GetPartById(relId);
continue;
}
catch (ArgumentOutOfRangeException)
{
try
{
ExternalRelationship tempEr = newContentPart.GetExternalRelationship(relId);
continue;
}
catch (KeyNotFoundException)
{
}
}
OpenXmlPart oldPart = oldContentPart.GetPartById(relId);
OpenXmlPart newPart = newContentPart.AddNewPart<DiagramDataPart>();
newPart.GetXDocument().Add(oldPart.GetXDocument().Root);
diagramReference.Attribute(R.dm).Value = newContentPart.GetIdOfPart(newPart);
AddRelationships(oldPart, newPart, new[] { newPart.GetXDocument().Root });
CopyRelatedPartsForContentParts(oldPart, newPart, new[] { newPart.GetXDocument().Root }, images);
// lo attribute
relId = diagramReference.Attribute(R.lo).Value;
try
{
OpenXmlPart tempPart = newContentPart.GetPartById(relId);
continue;
}
catch (ArgumentOutOfRangeException)
{
try
{
ExternalRelationship tempEr = newContentPart.GetExternalRelationship(relId);
continue;
}
catch (KeyNotFoundException)
{
}
}
oldPart = oldContentPart.GetPartById(relId);
newPart = newContentPart.AddNewPart<DiagramLayoutDefinitionPart>();
newPart.GetXDocument().Add(oldPart.GetXDocument().Root);
diagramReference.Attribute(R.lo).Value = newContentPart.GetIdOfPart(newPart);
AddRelationships(oldPart, newPart, new[] { newPart.GetXDocument().Root });
CopyRelatedPartsForContentParts(oldPart, newPart, new[] { newPart.GetXDocument().Root }, images);
// qs attribute
relId = diagramReference.Attribute(R.qs).Value;
try
{
OpenXmlPart tempPart = newContentPart.GetPartById(relId);
continue;
}
catch (ArgumentOutOfRangeException)
{
try
{
ExternalRelationship tempEr = newContentPart.GetExternalRelationship(relId);
continue;
}
catch (KeyNotFoundException)
{
}
}
oldPart = oldContentPart.GetPartById(relId);
newPart = newContentPart.AddNewPart<DiagramStylePart>();
newPart.GetXDocument().Add(oldPart.GetXDocument().Root);
diagramReference.Attribute(R.qs).Value = newContentPart.GetIdOfPart(newPart);
AddRelationships(oldPart, newPart, new[] { newPart.GetXDocument().Root });
CopyRelatedPartsForContentParts(oldPart, newPart, new[] { newPart.GetXDocument().Root }, images);
// cs attribute
relId = diagramReference.Attribute(R.cs).Value;
try
{
OpenXmlPart tempPart = newContentPart.GetPartById(relId);
continue;
}
catch (ArgumentOutOfRangeException)
{
try
//.........这里部分代码省略.........
示例2: CopyRelatedImage
private static void CopyRelatedImage(OpenXmlPart oldContentPart, OpenXmlPart newContentPart, XElement imageReference, XName attributeName,
List<ImageData> images)
{
string relId = (string)imageReference.Attribute(attributeName);
if (string.IsNullOrEmpty(relId))
return;
try
{
// First look to see if this relId has already been added to the new document.
// This is necessary for those parts that get processed with both old and new ids, such as the comments
// part. This is not necessary for parts such as the main document part, but this code won't malfunction
// in that case.
try
{
OpenXmlPart tempPart = newContentPart.GetPartById(relId);
return;
}
catch (ArgumentOutOfRangeException)
{
try
{
ExternalRelationship tempEr = newContentPart.GetExternalRelationship(relId);
return;
}
catch (KeyNotFoundException)
{
// nothing to do
}
}
ImagePart oldPart = (ImagePart)oldContentPart.GetPartById(relId);
ImageData temp = ManageImageCopy(oldPart, newContentPart, images);
if (temp.ResourceID == null)
{
ImagePart newPart = null;
if (newContentPart is MainDocumentPart)
newPart = ((MainDocumentPart)newContentPart).AddImagePart(oldPart.ContentType);
if (newContentPart is HeaderPart)
newPart = ((HeaderPart)newContentPart).AddImagePart(oldPart.ContentType);
if (newContentPart is FooterPart)
newPart = ((FooterPart)newContentPart).AddImagePart(oldPart.ContentType);
if (newContentPart is EndnotesPart)
newPart = ((EndnotesPart)newContentPart).AddImagePart(oldPart.ContentType);
if (newContentPart is FootnotesPart)
newPart = ((FootnotesPart)newContentPart).AddImagePart(oldPart.ContentType);
if (newContentPart is ThemePart)
newPart = ((ThemePart)newContentPart).AddImagePart(oldPart.ContentType);
if (newContentPart is WordprocessingCommentsPart)
newPart = ((WordprocessingCommentsPart)newContentPart).AddImagePart(oldPart.ContentType);
if (newContentPart is DocumentSettingsPart)
newPart = ((DocumentSettingsPart)newContentPart).AddImagePart(oldPart.ContentType);
if (newContentPart is ChartPart)
newPart = ((ChartPart)newContentPart).AddImagePart(oldPart.ContentType);
if (newContentPart is NumberingDefinitionsPart)
newPart = ((NumberingDefinitionsPart)newContentPart).AddImagePart(oldPart.ContentType);
if (newContentPart is DiagramDataPart)
newPart = ((DiagramDataPart)newContentPart).AddImagePart(oldPart.ContentType);
if (newContentPart is ChartDrawingPart)
newPart = ((ChartDrawingPart)newContentPart).AddImagePart(oldPart.ContentType);
temp.ResourceID = newContentPart.GetIdOfPart(newPart);
temp.WriteImage(newPart);
imageReference.Attribute(attributeName).Value = temp.ResourceID;
}
else
imageReference.Attribute(attributeName).Value = temp.ResourceID;
}
catch (ArgumentOutOfRangeException)
{
try
{
ExternalRelationship er = oldContentPart.GetExternalRelationship(relId);
ExternalRelationship newEr = newContentPart.AddExternalRelationship(er.RelationshipType, er.Uri);
imageReference.Attribute(R.id).Value = newEr.Id;
}
catch (KeyNotFoundException)
{
throw new DocumentBuilderInternalException("Source {0} is unsupported document - contains reference to NULL image");
}
}
}