Forum


Replies: 1   Views: 25
Dynamic images in the table

Posted by vitorsantosinfo  · 14-09-2023 - 11:54

Is there a way to display images in my table similar to the method replaceTableVariable?
where for each row of my table an image is displayed.

Posted by admin  · 14-09-2023 - 12:07

Hello,

Which method are you using to create the table?

If you are using addTable you can use WordFragments. For example:

$imageA = new WordFragment($docx);
$options = array(
    'src' => 'imageA.png'
);
$imageA->addImage($options);

$imageB = new WordFragment($docx);
$options = array(
    'src' => 'imageB.png'
);
$imageB->addImage($options);

$valuesTable = array(
    array(
        'Title A',
        'Title B',
    ),
    array(
        $imageA,
        $imageB,
    )
);

$docx->addTable($valuesTable);

In the sample included in the package examples/Core/addTable/sample_2.php you can find how to generate a table with contents using WordFragments.

WordFragments can also be used with replaceTableVariable and many other phpdocx methods.

Regards.