本文整理汇总了C#中OpenXmlPart.AddNewPart方法的典型用法代码示例。如果您正苦于以下问题:C# OpenXmlPart.AddNewPart方法的具体用法?C# OpenXmlPart.AddNewPart怎么用?C# OpenXmlPart.AddNewPart使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类OpenXmlPart
的用法示例。
在下文中一共展示了OpenXmlPart.AddNewPart方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的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
//.........这里部分代码省略.........