importContents

importContents

PREMIUM TRIAL / ADVANCED

Imports contents from a document.

Description
public importContents (string $document, array $referenceNode)
Parameters

document

DOCX to be imported.

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 links and lists), section, shape, table, table-row, table-cell, table-cell-paragraph.
contains string Contains a text string.
occurrence int or string 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.
Code samples

Example #1

Example #2

Release notes
  • phpdocx 15.0:
    • table-row, table-cell and table-cell-paragraph types.
  • phpdocx 14.0:
    • improved working with notes with external relationships.
  • phpdocx 13.5:
    • OLE objects.
    • multiple list level overrides.
  • phpdocx 13.0:
    • importEmbeddedFonts option.
    • OLE objects without bin extensions.
  • phpdocx 12.5:
    • links with mixed IDs and anchors.
    • OLE objects embedded in equations.
    • added new XML namespaces.
    • don't add webSettings and theme1 relationships if the first DOCX to be merged doesn't include them.
  • phpdocx 12.0:
    • improved embedded images in shapes, SVG images, numbering styles applied to custom styles, multiple altChunk tag, hyperlinks in images tags with the same ID and external charts.
    • improved working with multiple sections that contain multiple headers and footers.
  • phpdocx 11.0:
    • override styles in level lists.
  • phpdocx 10.0:
    • new method.