Forum


Replies: 1   Views: 2879
How do i make table full width?
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  · 31-08-2021 - 14:26

Hello,

You can use the tableWidth option by applying a 100 pct value:

'tableWidth' => array('type' => 'pct', 'value' => 100),

or a fixed width (dxa):

'tableWidth' => array('type' => 'dxa', 'value' => 8500),

and also use columnWidths:

'columnWidths' => array(2125,2125,2125,2125),

MS Word allows working with auto values (pct and auto sizes), so you don't need to set the exact cell widths, but some DOCX readers can't work with auto values as MS Word does. Google Docs has some limitations when working with DOCX documents.

For example, the following code generates a table from left margin to right margin using the default page size by setting specific sizes instead of auto values:

$docx = new CreateDocx();

$values = array(
    array(
        11,
        12,
        13,
        14
    ),
    array(
        21,
        22,
        23,
        24
    ),

);

$options = array(
    'columnWidths' => array(2125,2125,2125,2125),
    'tableWidth' => array('type' => 'dxa', 'value' => 8500),
);

$docx->addTable($values, $options);

$docx->createDocx('output');

Both the tableWidth (dxa type) and columnWidths options use twips (Twentieth of a Point) as their unit of measurement. As a reference, 8500 twips correspond to the default A4-size section.

Regards.