Content

Fields

Fields are placeholders for values computed by word processors.

Fields are placeholders for values computed by word processors. A common use case for fields is to insert document metadata or properties such as title, author, subject, etc. The following code demonstrates how a field formulated with the document title can be inserted into a paragraph:

content.Paragraph(p => {
    p.Text("The document title is: ")
    p.Field("TITLE");
});

It is important to reiterate that field values are not computed by the library; this is the job of word processors when the document is displayed or printed. The library sets the initial display value of fields as the field formula surrounded by braces. For example, the previous code would result in the following output until the document is updated:

The document title is: { TITLE \* MERGEFORMAT }

Again, field values are not computed by the library! Fields must be computed by a word processor when the document is opened, printed, and/or exported. The initial display value of fields is the field formula surrounded by braces.
Fields displaying page numbers in headers and footers are typically computed automatically by word processors when a document is opened.

Field Codes

The following tables list common field codes. Refer to ECMA-376, Part 1, Section 17.16 for more information on fields, field codes, and their syntax.

Document Metadata

CodeDescription
TITLEThe document's title.
SUBJECTThe document's subject.
COMMENTSThe document's description; alternatively the comments relating to the document.
AUTHORThe document author's name.
FILENAMEThe document's filename.
LASTSAVEDBYThe name of the user who last modified/saved the document.
DOCPROPERTY CATEGORYThe document's category.
DOCPROPERTY COMPANYThe company associated with document.
DOCPROPERTY MANAGERThe manager associated with the document.

Date and Time

CodeDescription
DATEThe current date and time.
CREATEDATEThe date and time the document was created.
SAVEDATEThe date the time the document was last modified/saved.
PRINTDATEThe date and time the document was last printed/exported.

Numbering

FluentWriter provides aliases for inserting page numbers. See Page Numbers for details.
CodeDescription
PAGEThe current page number.
NUMPAGESThe number of pages in the document.
SECTIONThe current section number.
SECTIONPAGESThe number of pages in the current section.

Styling

Fields values are styled just like text:

content.Paragraph(p => {
    p.Text("Document title: ").Bold();
    p.Field("TITLE").Italic();
});

Document title: { TITLE \* MERGEFORMAT }