0

I have been using Syncfusion DocIO for generating MS Word documents from my .net applications (winforms). So far I have dealt with plain text and it is fairly straightforward to insert text in a word document template where bookmarks serve as reference points for text insertion.

I am navigating the bookmarks using BookmarksNavigator.MoveToBookmark() . Now I need to insert an image at a bookmark but I am at a loss at how to go about it.

Please help...

Thanks.

4

3 回答 3

2

专门用于将其添加到书签:

            //Move to the specified bookmark
            bk.MoveToBookmark(bookmark);

            //Insert the picture into the specified bookmark location
            bk.DeleteBookmarkContent(true);

            // we assume the text is a full pathname for an image file
            // get the image file
            System.Drawing.Image image = System.Drawing.Image.FromFile(sText);

            IWParagraph paragraph = new WParagraph(document);
            paragraph.AppendPicture(image);
            bk.InsertParagraph(paragraph);
于 2011-11-22T21:31:17.923 回答
1
private System.Drawing.Image LoadSignature(string sFileName)
{
    string sImagePath = sFileName;
    System.Drawing.Image image = System.Drawing.Image.FromFile(sImagePath);
    return image;
}

private void MergeSignature(WordDocument doc, string sFile, string sBalise)
{
    System.Drawing.Image iSignature = LoadSignature(sFile);
    WordDocument ImgDoc = new WordDocument();
    ImgDoc.AddSection();
    ImgDoc.Sections[0].AddParagraph().AppendPicture(iSignature);

    if (iSignature != null)
    {
        TextSelection ts = null ;
        Regex pattern = new Regex(sBalise);
        ts = doc.Find(pattern);

        if (ts != null)
        {
            doc.ReplaceFirst = true;
            doc.Replace(pattern, ImgDoc, false);
        }
    }
    iSignature.Dispose();
}
于 2009-08-23T16:33:05.230 回答
0

见这里:https ://help.syncfusion.com/file-formats/docio/working-with-mailmerge

1) 您应该创建名为“Template.docx”的 docx 文件。该文件将用作模板。在您的 docx 文件中创建 MergeField 类型的字段。 在此处输入图像描述

2) 使用名称Image:Krishna创建 MergeFiled 在此处输入图像描述

3)

using Syncfusion.DocIO.DLS;
using System.Drawing;

public class Source
{
    public Image Krishna { get; set; } = Image.FromFile(@"C:\1.png");
}

并生成代码:

public static void Generate()
{
  WordDocument doc = new WordDocument("Template.docx");

  Source data = new Source();
  var dataTable = new MailMergeDataTable("", new Source[] { data });

  doc.MailMerge.ExecuteGroup(dataTable);

  doc.Save("result.docx");
  doc.Close();
}
于 2018-10-18T09:43:14.493 回答