Forum


Replies: 1   Views: 80
How to add table inside table

Posted by admin  · 14-10-2024 - 06:02

Hello,

You can use WordFragments to add content to tables (such as texts with styles, images, HTML, links,  other tables, charts...). You can add WordFragments in new contents, for example using addTable:

$valuesTable = array(
    array(
        'Title A',
        'Title B',
        'Title C',
    ),
    array(
        'Line A',
        $wordFragment1,
        $wordFragment2,
    )
);

$docx->addTable($valuesTable);

and replacing placeholders in templates, for example using replaceTableVariable:

$data = array(
                array(
                    'ITEM' => $wordFragment1,
                    'REFERENCE' => $wordFragment2,
                    'PRICE' => '5.45'
                ),
                array(
                    'ITEM' => $wordFragment3,
                    'REFERENCE' => $wordFragment4,
                    'PRICE' => '30.12'
                ),
                array(
                    'ITEM' => $wordFragment5,
                    'REFERENCE' => $wordFragment6,
                    'PRICE' => '7.00'
                )
        );

$docx->replaceTableVariable($data);

We recommend you check the samples included in the package, which illustrate adding WordFragments to tables using addTable, replaceTableVariable, and many other methods.

On https://www.phpdocx.com/documentation/practical/wordfragments-and-wordml you can read more information about working with WordFragments with phpdocx.

Regards.