如何为已经在另一部分中添加的图像添加条目到现有的relationshipid
?
例如:我有一个带页眉和页脚的Word文档。我使用代码headerPart.AddImagePart(ImagePartType)
将图片(例如A.gif)添加到标题,然后使用流对其调用FeedData
。
现在我也希望在页脚中显示相同的图像,但是不要添加相同图像的重复条目,而是引用先前为页眉添加的相同图像。
如何将条目添加到footer.xml.rels文件以引用与标题相同的relationShipId
?
下面是代码:1)添加一个新的图像部分,和2)返回一个ID给添加的图像:
ImagePart imagePart = addImagePart(partType, existingRelationShipId);
using (FileStream stream = new FileStream(imageFilePath, FileMode.Open))
{
imagePart.FeedData(stream);
}
headerPart= currentPart;
return headerPart.GetIdOfPart(imagePart);
要仅添加对现有图像的引用,请使用之前(上面)获得的ID:
var extPart = headerPart.GetPartById(existingRelationShipId);
footerPart.AddPart(extPart, existingRelationShipId);