在word文档中插入具有映射到xml的内容控件的图像 [英] Insert image from database in word document that have content control mapped to xml

查看:570
本文介绍了在word文档中插入具有映射到xml的内容控件的图像的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

1)我在docx中有单词模板,内容控件用xml映射。

1) I have word template in docx with content controls mapped with xml.

2)我遍历sdtblocks的集合并到达我知道的地步我必须从数据库中成像。

2) I loop through the collection of sdtblocks and get to the point where i know that i have to image from database.

var sdtPic = mainPart.Document.Descendants< SdtBlock>()。其中​​(s => s.SdtProperties.InnerXml.Contains(" DbPicture") ;))。FirstOrDefault();

var sdtPic = mainPart.Document.Descendants<SdtBlock>().Where(s => s.SdtProperties.InnerXml.Contains("DbPicture")).FirstOrDefault();

直到这一点,代码工作正常。我确实得到了sdtPic对象。 我需要在stdPic上插入数据库中的图片。可以要求多张图片,所以FirstOrDefault 将隐藏到列表,我将不得不循环通过列表插入图片。

Till this point the code works fine. I do get sdtPic object.  I need to insert picture from database at stdPic. There can be requirement for multiple pictures so FirstOrDefault  will covert to List and i will have to Loop through the List to insert pictures.

是否有我可以参考的文章或代码样本。

Is there an article or code sampe that i can refer to.

感谢任何帮助。

推荐答案

您好mac73,

Hi mac73,

感谢您的提问。

由于您已获得SdtBlock元素,要将图像插入这些内容控件,我建议您使用Productivity Tool按以下步骤查看示例代码:

Since you have got the SdtBlock element, to insert the images into those content controls, I suggest you using the Productivity Tool to see the sample code by the following steps:

1.     创建包含图片内容控件的docx文档并保存,例如"source.docx"。

1.      Create a docx document with an image content control and save it, such as “source.docx”.

2.     将图像添加到docx的内容控件中并将其另存为"target.docx"。

2.      Add an image to the content control to the docx and save it as “target.docx”.

3.     打开工具;点击"比较文件"比较'source.docx”和"target.docx”文件。

3.      Open the Tool; click "Compare Files" to compare the “source.docx” and “target.docx” files.

4.     在"文件比较"中选项卡,单击"查看包裹代码"以查看有关如何将图像添加到内容控件的完整示例代码。

4.      In the "File Comparison" tab, click "View Package Code" to see the complete sample code on how to add an image to the content control.

我不确定它是否符合您的要求。如果没有,您能否详细描述您的要求或情景?如果您有任何疑问,请告诉我。

I'm not sure if it meets your requirement. If not, could you describe your requirement or scenario in detail? If you have any question, please let me know.

谢谢,

Lu


这篇关于在word文档中插入具有映射到xml的内容控件的图像的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆