简体   繁体   English

使用OpenXML SDK 2.5将图片添加到QuickPart自动图文集

[英]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. 我尝试使用openxml sdk在自动文本中添加图片,现在的问题是我可以添加自动文本,但是当前无法显示图片。 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. 这与关系ID有关,但是当我尝试从原始模板中添加具有相同ID的图片时,出现错误,表明当前ID已被使用。

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. 我认为在Save()之后,您应该调用Close()方法。 That should hopefully fix it. 希望应该可以解决它。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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