|
//Loads a template document
WordDocument document = new WordDocument("Template.docx", FormatType.Docx);
//Creates new paragraph.
WParagraph paragraph = new WParagraph(document);
//Appends mail merge field to the paragraph.
paragraph.AppendField("SimpleField", FieldType.FieldMergeField);
//Initializes text body part
TextBodyPart bodyPart = new TextBodyPart(document);
bodyPart.BodyItems.Add(paragraph);
//Replaces a particular text with the text body part,
//taking into consideration case sensitive, whole word, and formatting options.
document.Replace("text", bodyPart, true, true, true);
//Saves and closes the document document.Save("Sample.docx");
document.Close(); |