Forum


Replies: 1   Views: 154
How to add table inside table
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  · 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.