[英]Add image to a placeholder of word template
大家好我所有的代碼都有Open XML SDK在Microsoft Word文檔中找到MERGEFIELD並用提供的數據替換它們,這很好但我想用現在的圖像替換提供的字符串 。
鏈接代碼:
https://www.codeproject.com/Articles/38575/Fill-Mergefields-in-docx-Documents-without-Microso
using (WordprocessingDocument docx = WordprocessingDocument.Open(stream, true))
{
// 2010/08/01: addition
ConvertFieldCodes(docx.MainDocumentPart.Document);
// first: process all tables
foreach (var field in docx.MainDocumentPart.Document.Descendants<SimpleField>())
{
string fieldname = GetFieldName(field, out switches);
// I will get fieldname "ImgLogo" and then I want to add an Image at this position.
}
}
我將獲得如上所示的fieldname“ImgLogo”,然后我想在此位置添加一個Image。 完整代碼顯示在上面的鏈接中。
在這里幫助我在此先感謝
您可以使用mergefield if語句。 在完成將圖像粘貼到if語句的else段之后,寫出您的語句。
https://wordmvp.com/FAQs/MailMerge/MMergeIfFields.htm
按Alt + F9以word / excel顯示合並域代碼。 如果要編輯模板文檔而不是最終產品。 因為你在合並之后看不到這些字段。
當你合並你的圖片時,它將覆蓋兩個{MERGEFIELD MergeImage}字段。 當它覆蓋它們時,{MERGEFIELD MergeImage} =“”將不為真,它將顯示您的圖像而不是占位符。 如上所述,占位符圖像應粘貼到=“此處粘貼占位符”。
這與合並圖像之前的工作方式相同,{MERGEFIELD MergeImage}等於空白字符串。
例如
{ IF { MERGEFIELD MergeImage } = "" "Paste Placeholder here" "{ MERGEFIELD MergeImage }" }
分解以上:
{ IF CONDITION "TRUE" "FALSE" }
如果沒有合並你將獲得占位符,否則你將獲得合並的圖像。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.