Forum


Replies: 1   Views: 1433
Add 2 tables inline
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  · 06-01-2021 - 10:32

Hello,

MS Word requires adding a paragraph between tables:

https://answers.microsoft.com/en-us/msoffice/forum/msoffice_word-mso_win10-mso_2013_release/remove-space-after-table/1f651f2d-e630-4d53-ab1e-a3a7418faf21?auth=1

https://wordribbon.tips.net/T011729_Spacing_Before_and_After_Tables.html

If you open MS Word, a table is added and then you try to add a new table without adding at least a paragraph you can check MS Word doesn't allow adding the new table.

The best solution is generating a single table (instead of two) or adding a paragraph with the minimum space (https://stackoverflow.com/questions/59106925/html-to-doc-add-minimum-space-between-tables), for example, using phpdocx to set the minimum space between tables:

$docx = new CreateDocx();

$valuesTable = array(
    array('A.1', 'A.2'),
    array('B.1', 'B.2')
);

$paramsTable = array(
    'border' => 'single',
);

$docx->addTable($valuesTable, $paramsTable);

// new paragraph with the minimum size
$docx->addText('', array('fontSize' => 1, 'spacing' => 0, 'spacingBottom' => 0, 'spacingTop' => 0, 'lineSpacing' => 0));

// remove borderTop for the cells of the first row of the second table to avoid adding two borders
$col_1_1 = array(
    'value' => 'N.1', 
    'border' => 'single',
    'borderTop' => 'nil',
);

$col_1_2 = array(
    'value' => 'N.2', 
    'border' => 'single',
    'borderTop' => 'nil',
);

$valuesTable = array(
    array($col_1_1, $col_1_2),
);

$paramsTable = array(
    'border' => 'single',
);

$docx->addTable($valuesTable, $paramsTable);

If you need to add a lot of tables, instead of setting the syles in each paragraph to separate paragrahs you can create a custom paragraph style using customParagraphStyle.

Regards.