简体   繁体   中英

Add Pictures to QuickPart Autotext with OpenXML SDK 2.5

I try to add pictures in a autotext with the openxml sdk, the problem now is that i can add the autotexts but the pictures cannot currently be displayed. That has something to do with the relationship id´s, but when i try to add the picture with the same id from the original template, i get the error that the current id is already in use.

to add the pictures i try the following code:

foreach (DocumentBinaryPart relatedDocumentPart in AutotextContainer.RelatedDocumentParts.Where(x => x.Type == "ImagePart"))
     {
        XmlDocument document = new XmlDocument();
        ImagePart imagePart = glossaryDocument.AddImagePart(relatedDocumentPart.ImageType, relatedDocumentPart.relationshipid);

        using (Stream stream = new MemoryStream(relatedDocumentPart.Data))
        {
           imagePart.FeedData(stream);
        }
mainDocumentPart.GlossaryDocumentPart.GlossaryDocument.Save();

I think after the Save() you should call the Close() method. That should hopefully fix it.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM