Analyzing your prompt, please hold on...
An error occurred while retrieving the results. Please refresh the page and try again.
There are several different ways to insert fields into a document:
In this article, we will look at each way in more detail and analyze how to insert certain fields using these options.
In Aspose.Words the insert_field method is used to insert new fields into a document. The first parameter accepts the full field code of the field to be inserted. The second parameter is optional and allows the field result of the field to be set manually. If this is not supplied then the field is updated automatically. You can pass null or empty to this parameter to insert a field with an empty field value. If you are not sure about the particular field code syntax, create the field in Microsoft Word first and switch to see its field code.
The following code example shows how to inserts a merge field into a document using DocumentBuilder:
The following code example shows how to inserts a merge field with German locale into a document using DocumentBuilder:
The same technique is used to insert fields nested within other fields.
The following code example shows how to insert fields nested within another field using DocumentBuilder:
A language identifier is a standard international numeric abbreviation for the language in a country or geographical region. With Aspose.Words, you can specify Locale at field level. The locale_id property gets or sets the locale ID of the field.
The following code example shows how to make use of this option:
If you want to insert untyped/empty fields ({}) just like Microsoft Word allows, you can use the insert_field method with the FieldType.FIELD_NONE parameter. To insert a field into a Word document, you can press “Ctrl + F9” key combination.
The following code example shows how to insert an empty field into the document:
The alternative way to insert fields in Aspose.Words is the FieldBuilder class. It provides fluent interface to specify field switches and argument values as text, nodes or even nested fields.
The following code example shows how to insert a field into a document using FieldBuilder:
You can also insert various types of fields using Aspose.Words Document Object Model (DOM). In this section, we will look at a few examples.
The MERGEFIELD field in Word document can be represented by the FieldMergeField class. You can use FieldMergeField class to perform the following operations:
The following code example shows how to add a Merge Field using DOM to a paragraph in a document:
ADDRESSBLOCK field into a Document using DOMThe ADDRESSBLOCK field is used to insert a Mail Merge address block in Word document. ADDRESSBLOCK field in Word document can be represented by the FieldAddressBlock class. You can use FieldAddressBlock class to perform the following operations:
The following code example shows how to add the Mail Merge ADDRESSBLOCK Field using DOM to a paragraph in a document:
ADVANCE field into a Document without using DocumentBuilderThe ADVANCE field is used to offset subsequent text within a line to the left, right, up or down. The ADVANCE field in Word document can be represented by the FieldAdvance class. You can use the FieldAdvance class to perform the following operations:
The following code example shows how to add the ADVANCE Field using DOM to a paragraph in a document.
ASK field into a Document without using DocumentBuilderThe ASK field is used to prompt the user for text to assign to a Bookmark in Word document. ASK field in Word document can be represented by the FieldAsk class. You can use the FieldAsk class to perform the following operations:
The following code example shows how to add the ASK Field using DOM to a paragraph in a document:
AUTHOR field into a Document without using DocumentBuilderThe AUTHOR field is used to specify the name of Document’s author from the Document properties. The AUTHOR field in Word document can be represented by the FieldAuthor class. You can use the FieldAuthor class to perform the following operations:
The following code example shows how to add the AUTHOR Field using DOM to a paragraph in a document:
INCLUDETEXT field into a Document without using DocumentBuilderThe INCLUDETEXT field inserts the text and graphics contained in the document named in the field code. You can insert the entire document or a portion of the document referred to by a bookmark. This field in Word document is represented by INCLUDETEXT. You can use FieldIncludeText class to perform the following operations:
The following code example shows how to add the INCLUDETEXT field using DOM to a paragraph in a document:
TOA field into a Document without using DocumentBuilderThe TOA (Table of Authorities) field builds and inserts a table of authorities. The TOA field collects entries marked by TA (Table of Authorities Entry) fields. Microsoft Office Word inserts the TOA field when you click Insert Table of Authorities in the Table of Authorities group on the References tab. When you view the TOA field in your document, the syntax looks like this:
{ TOA [Switches ] }
You can use the FieldToa class to perform the operations with the TOA field.
The following code example shows how to add the TOA field using DOM to a paragraph in a document:
Analyzing your prompt, please hold on...
An error occurred while retrieving the results. Please refresh the page and try again.