moveWordContent
- addBibliography
- addBookmark
- addBreak
- addCaption
- 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
- addTableAuthorities
- 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
moveWordContent


Moves contents in the document.
Description
public moveWordContent (array $referenceNodeFrom, array $referenceNodeTo, [string $location, bool $forceAppend])
Parameters
referenceNodeFrom
An array to get the source refence node.
The possible keys and values of this array are:
Key | Type | Description |
---|---|---|
type | string | * (all, default value), break, chart, endnote (content reference), footnote (content reference), image, list, math, paragraph (also for bookmarks, 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. |
referenceNodeTo
An array to get the destination refence node.
The possible keys and values of this array are:
Key | Type | Description |
---|---|---|
type | string | * (all, default value), break, chart, endnote (content reference), footnote (content reference), image, list, math, paragraph (also for bookmarks, links and lists), section, shape, table, table-row, table-cell, table-cell-paragraph. |
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) or before.
forceAppend
If true appends the WordFragment if the reference node could not be found (false as default).
Exceptions
Method not available.
Code samples
Example #1
x
1
require_once 'classes/CreateDocx.php';
2
3
$docx = new CreateDocx();
4
5
$text = 'Lorem ipsum dolor sit amet, consectetur adipisicing elit, ' .
6
'sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut ' .
7
'enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut' .
8
'aliquip ex ea commodo consequat. Duis aute irure dolor in reprehenderit ' .
9
'in voluptate velit esse cillum dolore eu fugiat nulla pariatur. ' .
10
'Excepteur sint occaecat cupidatat non proident, sunt in culpa qui ' .
11
'officia deserunt mollit anim id est laborum.';
12
13
$paragraphOptions = array(
14
'bold' => true,
15
'font' => 'Arial',
16
);
17
18
$docx->addText($text, $paragraphOptions);
19
20
$text = 'Sed ut perspiciatis unde omnis iste natus error sit voluptatem ' .
21
'accusantium doloremque laudantium, totam rem aperiam, eaque ipsa quae ' .
22
'ab illo inventore veritatis et quasi architecto beatae vitae dicta sunt ' .
23
'explicabo. Nemo enim ipsam voluptatem quia voluptas sit aspernatur aut ' .
24
'odit aut fugit, sed quia consequuntur magni dolores eos qui ratione voluptatem ' .
25
'sequi nesciunt.';
26
27
$docx->addText($text, $paragraphOptions);
28
29
$text = 'Donec blandit ex nec lectus iaculis imperdiet. Donec a dictum odio. ' .
30
'Morbi viverra, urna eu consectetur tincidunt, ex urna commodo turpis, ut euismod ' .
31
'diam augue ac tellus. Mauris eget posuere orci. Etiam vehicula tincidunt ligula ac ' .
32
'molestie. Nullam sit amet lectus nec nisl facilisis aliquet. ' .
33
'Maecenas convallis vel ipsum rhoncus dictum. ';
34
35
$docx->addText($text, $paragraphOptions);
36
37
$referenceNodeFrom = array(
38
'type' => 'paragraph',
39
'contains' => 'Donec',
40
);
41
42
$referenceNodeTo = array(
43
'type' => 'paragraph',
44
'contains' => 'Lorem',
45
);
46
$docx->moveWordContent($referenceNodeFrom, $referenceNodeTo, 'after');
47
48
$docx->createDocx('output');
49
Release notes
- phpdocx 15.5:
- math type.
- phpdocx 15.0:
- table-row, table-cell and table-cell-paragraph types.
- phpdocx 12.0:
- improved working with multiple sections that contain multiple headers and footers.
- phpdocx 8.2:
- improved performance.
- phpdocx 7.0:
- range of elements, iterate all elements not only the first one, siblings.
- phpdocx 6.5:
- new method.