addTableContents

addTableContents

TRIAL / ADVANCED / PREMIUM

Inserts a Table of Contents (TOC) into the Word document.

Description
public addTableContents ( [array $options [, array $legend [, string $stylesTOC ]]] )

This method allows to include a Table of Contents in the Word document.

Parameters

options

The possible keys and values are:

Key Type Description
autoUpdate boolean If true it will try to update the TOC when first opened.
displayLevels string Must be of the form "1-3" where the first number is the start level an the second the end level. If not defined all existing levels are shown.

legend

The possible keys and values are:

Key Type Description
text string The placeholder text that will be shown if the autoupdate option is not activated.
Styles from addText.

stylesTOC

Path to a DOCX. This optional parameter allows to extract the TOC styles from an existing Word document so the embedded TOC can be fully customized.

Code samples

Example #1

The resulting Word document looks like:

Release notes
  • phpdocx 11.0:
    • apply custom paragraph styles to the generated TOC contents.
  • phpdocx 8.0:
    • supported as WordFragment.