insertWordFragment

insertWordFragment

ADVANCED / PREMIUM BASIC

Inserts elements in the document.

Description
public insertWordFragment (WordFragment $wordFragment, array $referenceNode, [string $location, bool $forceAppend])
Parameters

wordFragment

WordFragment to be inserted.

referenceNode

An array to get the refence node.
The possible keys and values of this array are:

Key Type Description
type string * (all, default value), bookmark, break, chart, endnote (content reference), footnote (content reference), image, list, paragraph (also for lists and links), section, shape, table.
contains string Contains a text string.
occurrence int Exact occurrence (int) or range of contents (e.g.: 2..9, 2.., ..9) (string) or first() or last(). If empty iterate all elements.
attributes array Contains a specific attribute key and value.
parent string Main document body as default, allows to set any parent or a specific one. w:body (default), '/' (any parent) or any other specific parent (/w:tbl/, /w:tc/, /w:r/...).
customQuery string Custom xpath query, overwrites any other reference.

location

After (default), before, inlineBefore or inlineAfter. Inline locations don't create a new w:p and add the WordFragment before or after the referenceNode (only inline elements).

forceAppend

If true appends the WordFragment if the reference node could not be found (false as default).

Code samples

Example #1

Example #2