importContents
- addBibliography
- addBookmark
- addBreak
- addChart
- addCitation
- addComment
- addCrossReference
- addDateAndHour
- addEndnote
- addExternalFile
- addFootnote
- addFormElement
- addHeading
- addImage
- addLink
- addList
- addMathEquation
- addMergeField
- addOLE
- addOnlineVideo
- addPageNumber
- addShape
- addSimpleField
- addSource
- addStructuredDocumentTag
- addSVG
- addTab
- addTable
- addTableContents
- addTableFigures
- addText
- addTextBox
- addWordFragment
- addWordML
- embedHTML
- addBackgroundImage
- addFooter
- addFooterSection
- addHeader
- addHeaderSection
- addLineNumbering
- addMacroFromDoc
- addPageBorders
- addProperties
- addSection
- createDocx
- createDocxAndDownload
- createCharacterStyle
- createListStyle
- createParagraphStyle
- createTableStyle
- docxSettings
- embedFont
- importChartStyle
- importHeadersAndFooters
- importListStyle
- importStyles
- importStylesWordDefault
- modifyPageLayout
- parseStyles
- removeFooters
- removeHeaders
- setBackgroundColor
- setDecimalSymbol
- setDefaultFont
- setDocumentDefaultStyles
- setEncodeUTF8
- setLanguage
- setMarkAsFinal
- setRTL
- clearBlocks
- cloneBlock
- deleteBlock
- getTemplateVariables
- getTemplateVariablesType
- modifyInputFields
- modifyMergeFields
- processTemplate
- removeTemplateVariable
- removeTemplateVariableImage
- replaceBlock
- replaceListVariable
- replacePlaceholderImage
- replaceTableVariable
- replaceVariableByExternalFile
- replaceVariableByHtml
- replaceVariableByText
- replaceVariableByWordFragment
- replaceVariableByWordML
- setTemplateSymbol
- setTemplateBlockSymbol
- tickCheckboxes
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, math, 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.5:
- math type.
- inks contents.
- SmartArt contents.
- extra check to parse numbering styles.
- prevent duplicated numbering IDs when calling the method multiple times using the same document.
- handle invalid OOXML IDs assigned to images in shapes.
- added new XML namespaces to the default numbering base XML template.
- 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.