Word field codes explained

25 October 2024By Alice

ONLYOFFICE Docs has just been updated to version 8.2 with new functions and improvements, such as field codes for text documents. Read this article to learn more about this feature and how to use it in ONLYOFFICE document editor.

Word field codes explained

What are field codes and when to use them?

Field codes are dynamic placeholders that allow you to automatically insert content into a Word document based on specific conditions. They are especially useful when you want to add information that might change, such as page numbers, dates, hyperlinks, or data from external sources like databases.

In other words, imagine you’re writing a document and you want it to always show the current date or without you having to type it in every time. Instead of writing the date yourself, you can use a field code that pulls the current date from your computer and inserts it into the document. Every time you open or update the document, the date will change to the correct one without you doing anything.

This feature helps you save time and make your document smarter: instead of adding information manually, field codes do it for you.

Field Codes in ONLYOFFICE

ONLYOFFICE document editor supports a wide variety of field codes, each with specific functions. Below is a list of the most frequently used field codes along with their syntax and switches (optional parameters that modify the field’s behavior):

1. MERGEFIELD

This field inserts a link to data from an external source (like a database or CSV file) into the current document. During a mail merge process, the content from the external source will replace the field code.

Syntax: { MERGEFIELD FieldName [Switches] }

Switches:

  • \b – Inserts text before the field if the field is not empty.
  • \f – Inserts text after the field if it is not empty.
  • \m – Marks the field as a mapped one.
  • \v – Enables vertical formatting.

2. PAGENUM

This field inserts the current page number.

  • Syntax: { PAGENUM }

3. PAGECOUNT

Inserts the total number of pages in the current document.

  • Syntax: { PAGECOUNT }

4. TOC (Table of Contents)

This field creates a table of contents based on heading styles, outline levels, or captions in your document.

  • Syntax: { TOC [Switches] }

Switches:

  • \b – Limits the table of contents to a bookmarked section of the document.
  • \h – Applies hyperlink formatting.
  • \t – Uses custom styles for table entries instead of default heading styles.
  • \o – Creates a table of contents based on document structure levels, ignoring custom TC fields.

5. PAGEREF

Inserts the page number of a bookmarked location in the document for cross-referencing purposes.

  • Syntax: { PAGEREF Bookmark [\* Format Switch] }

Switches:

  • \h – Creates a hyperlink to the specified bookmark.
  • \p – Inserts the relative position of the paragraph marked by the bookmark.

6. NUMPAGES

Displays the total number of pages in the document.

  • Syntax: { NUMPAGES }

7. HYPERLINK

Inserts a hyperlink to another location within the document, an external file, or a web page.

  • Syntax: { HYPERLINK “URL or Filename” [Switches] }

Switches:

  • \l – Links to a specific location within the document.
  • \n – Opens the link in a new window.
  • \t – Specifies the target for the hyperlink.

8. TIME and DATE

Inserts the current time or date based on the system settings.

  • Syntax for TIME: { TIME [\@ “Date-Time Format”] }
  • Syntax for DATE: { DATE [\@ “Date-Time Format”] }

Switches:

  • \@ – Specifies the format in which the time or date will be displayed.

9. FORMULA

This field performs calculations based on the formula provided.

  • Syntax: { = Formula [Bookmark] [\# Numeric Picture] }

10. SEQ (Sequence)

SEQ fields are used to number items such as chapters, figures, or tables in a sequential order. They can be updated automatically when you add, remove, or move elements.

  • Syntax: { SEQ Identifier [Switches] }

Switches:

  • \n – Inserts the next sequence number.
  • \r – Resets numbering to the specified value.
  • \s – Starts numbering based on outline level.

11. STYLEREF

Adds the text formatted with a specific style to headers or footers. It can display the first or last occurrence of the style on the current page, useful for creating running headers or footers.

  • Syntax: { STYLEREF StyleIdentifier [Switches] }

Switches:

  • \p – Displays the relative position of the paragraph styled with the specified format.

12. ASK

Prompts the user to enter information, which is then stored as a bookmark in the document.

  • Syntax: { ASK Bookmark “Prompt” [Switches] }

Switches:

  • \d – Inserts default text if the user does not provide input.

Inserting a field code into a Word document

With an easy example, we will demonstrate how to insert the current date into your Word document using the field code. This practice is useful when you want to include dates in your documents, such as reports or meeting minutes, where the exact date is important.

1. Open your document in ONLYOFFICE Document Editor.

2. Place your cursor where you want the current date to appear in the document, then navigate to the Insert tab in the toolbar.

Word field codes explained

3. Click on the Field button.

Word field codes explained

4. In the dialogue box, enter the field code for the current date in the format you prefer.

Word field codes explained

5. Click OK to insert.

Word field codes explained

The field will display the date when the document was last updated.

To update this field:

1. Right-click on the date.

2. Select Update Field to refresh it.

Word field codes explained

And that’s it! This is just one of the new functions you will find in the latest versione of our editors. Watch this video to explore other features:

Want to try the editors in function yourself? Get ONLYOFFICE right now, it’s free.

START ONLINE       GET DESKTOP APP

Create your free ONLYOFFICE account

View, edit and collaborate on docs, sheets, slides, forms, and PDF files online.