JSON API - addSimpleField

addSimpleField

PREMIUM TRIAL / ADVANCED

Inserts a Word field.

Note

You are reading the JSON API documentation. For the PHP API method please go to addSimpleField.

This method allows to insert different types of Word fields into the Word document.

Among the automatic fields that you may insert are:

  • AUTHOR
  • COMMENTS
  • DOCPROPERTY
  • FILENAME
  • FILESIZE
  • KEYWORDS
  • LASTSAVEDBY
  • NUMCHARS
  • NUMPAGES
  • NUMWORDS
  • SUBJECT
  • TEMPLATE
  • TITLE

Beware that, of course, some of these fields (like, for example, AUTHOR) have to be previously defined in the Word document. This can be achieved either via the use of a customized base template or with the help of the addProperties method.

There are specific methods for the insertion of dates and page numbers that allow for a further customization of the resulting field. If the updateFields option is not set to true, in certain cases, the user may need to press F9 in the MS Word interface to update the field value. Please, check for each particular case in the resulting Word document.

JSON data

Styles from addText can be used.

Key Description
name The field value.
type The possible values are: date, numeric or general.
format This requires a working knowledge of the Word simple fields available formats (see, for example, this web page). Beware that you should omit the \*, \# and the \@ chunks that are already taken into account in the type parameter. The default value is empty.
doNotShadeFormData If true does not shade the corresponding field. Default value is false.
updateFields If true the user will be prompted to update the field data on opening the ord document. Check case by case if you need to activate this property. The default value is false.
Code samples

Example #1

Release notes
  • phpdocx 18.0:
    • new action.