代码之家  ›  专栏  ›  技术社区  ›  user581157

引用已添加到页眉以在页脚中引用的现有图像

  •  0
  • user581157  · 技术社区  · 5 年前

    如何向现有的 relationshipid 对于已经添加到另一部分的图像?

    例如:我有一个带有页眉和页脚的Word文档。我使用代码在标题中添加一个图像,比如A.gif headerPart.AddImagePart(ImagePartType) FeedData 上面有一条小溪。

    现在我希望相同的图像也显示在页脚中,但不添加相同图像的重复条目,而是引用先前为页眉添加的相同图像。

    如何向 页脚.xml.rels relationShipId 为标题存在吗?

    0 回复  |  直到 5 年前
        1
  •  0
  •   Sabuncu    5 年前

    代码如下: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);

    对已获得的图像(仅对已获得的图像添加引用):

    var extPart = headerPart.GetPartById(existingRelationShipId);
    footerPart.AddPart(extPart, existingRelationShipId);