cloneWordContent

cloneWordContent

ADVANCED / PREMIUM TRIAL

Clones contents in the document.

Description
public cloneWordContent (array $referenceToBeCloned, array $referenceNodeTo, [string $location, bool $forceAppend])
Parameters

referenceToBeCloned

An array to get the refence node to be cloned.
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
$referenceToBeCloned = array(
38
    'type' => 'paragraph',
39
    'contains' => 'Donec',
40
);
41
42
$referenceNodeTo = array(
43
    'type' => 'paragraph',
44
    'contains' => 'Lorem',
45
);
46
$docx->cloneWordContent($referenceToBeCloned, $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 14.0:
    • generate new id and name attributes for drawing object non-visual property tags.
  • 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.
­
­