Forum


Replies: 4   Views: 2572
Replacevariablebywordfragment and mergedocx errors
Topic closed:
Please note this is an old forum thread. Information in this post may be out-to-date and/or erroneous.
Every phpdocx version includes new features and improvements. Previously unsupported features may have been added to newer releases, or past issues may have been corrected.
We encourage you to download the current phpdocx version and check the Documentation available.

Posted by admin  · 01-12-2017 - 19:27

Hello,

We have done some tests with your DOCX and we don't get any error. We have tested it with PHP 5.2 to PHP 7.1 on Linux, Windows and macOS with phpdocx 7.5 (the version you are using).

This is the script we have run using your templates:

<?php

require_once 'classes/MultiMerge.inc';

$docx = new CreateDocxFromTemplate('FBTemplate_Cat.docx');
$chart = new WordFragment($docx, "document");
$data = array(
    'legend' => array('Legend 1', 'Legend 2', 'Legend 3'),
    'data' => array(
        array(
            'name' => 'data 1',
            'values' => array(10, 20, 5),
        ),
        array(
            'name' => 'data 2',
            'values' => array(20, 60, 3),
        ),
        array(
            'name' => 'data 3',
            'values' => array(50, 33, 7),
        ),
    ),
);
$paramsChart = array(
    'data' => $data,
    'type' => 'barChart',
    'color' => 5,
    'sizeX' => 15,
    'sizeY' => 10,
    'chartAlign' => 'center',
    'legendPos' => 'none',
    'legendOverlay' => '0',
    'border' => '1',
    'hgrid' => '1',
    'vgrid' => '0',
    'showTable' => '1'
);
$chart->addChart($paramsChart);

$docx->replaceVariableByWordFragment(array('Ranking_1' => $chart), array('type' => 'inline'));

$docx->createDocx('output_3');

$merge = new MultiMerge();
$merge->mergeDocx('output_3.docx', array('Test_Front_Page.docx'), 'output_2.docx', array());

Please compare it with the one you are running. This script replaces the placeholder with a chart, then generates a DOCX and finally merges the documents; it doesn't return any error. Please check if your script read access to the DOCX and that both files exist before merging them.

Regards,