Fields
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 }
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
| Code | Description |
|---|---|
| TITLE | The document's title. |
| SUBJECT | The document's subject. |
| COMMENTS | The document's description; alternatively the comments relating to the document. |
| AUTHOR | The document author's name. |
| FILENAME | The document's filename. |
| LASTSAVEDBY | The name of the user who last modified/saved the document. |
| DOCPROPERTY CATEGORY | The document's category. |
| DOCPROPERTY COMPANY | The company associated with document. |
| DOCPROPERTY MANAGER | The manager associated with the document. |
Date and Time
| Code | Description |
|---|---|
| DATE | The current date and time. |
| CREATEDATE | The date and time the document was created. |
| SAVEDATE | The date the time the document was last modified/saved. |
| PRINTDATE | The date and time the document was last printed/exported. |
Numbering
| Code | Description |
|---|---|
| PAGE | The current page number. |
| NUMPAGES | The number of pages in the document. |
| SECTION | The current section number. |
| SECTIONPAGES | The 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 }
Document title: Invoice #8675309