Forums     Knowledge Base     OfficeWriter Online     
 
 
This documentation is for
OfficeWriter v3.8.1
.NET Platform

View Docs for Another
Version or Platform

Programmer's Reference > WordApplication API > MergeField

The MergeField Object

     extends Field



This class represents a merge field in a document. Merge fields are used in WordWriter templates as data placeholders.

To create a merge field, use Element.InsertMergeFieldBefore() or Element.InsertMergeFieldAfter().

The following sample demonstrates creating a merge field at the end of a new document and retrieving the first merge field of an existing document.



Examples:

[csharp]
// Insert a merge field at the end of a new document
WordApplication app = new WordApplication();
Document doc = app.Create();
MergeField mfield = doc.InsertMergeFieldAfter("FieldName", "FieldName");

// Get the first merge field of an existing document
WordApplication app = new WordApplication();
Document doc = app.Open(@"C:\sample.doc");
MergeField firstMergeField = doc.Elements(Element.Type.MergeField)[0];
[vbnet]
' Insert a merge field at the end of a new document
Dim app As New WordApplication()
Dim doc As Document = app.Create()
Dim mfield As Field = doc.InsertMergeFieldAfter("FieldName", "FieldName")

' Get the first merge field of an existing document
Dim app As New WordApplication()
Dim doc As Document = app.Open("C:\sample.doc")
Dim firstMergeField As MergeField = doc.Elements(Element.Type.MergeField)(0)


Please note that this object inherits methods and properties not shown here from the following objects:

This object does not have any properties defined.

MergeField Methods

ReturnsSignature and Description
String GetFieldName ( )
Returns the merge field's name



Copyright 2007 © SoftArtisans, Inc. All Rights Reserved.