I think after the Save()
you should call the Close()
method. That should hopefully fix it.
Add Pictures to QuickPart Autotext with OpenXML SDK 2.5
-
06-10-2022 - |
题
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();
解决方案
不隶属于 StackOverflow