Forum


Replies: 1   Views: 2479
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 applying a 100 pct value or a fixed width (dxa) and also use columnWidths.

MS Word allows working with auto values 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, so setting cell widths in the first row may be required. Google Docs has some limitations when working with DOCX documents.

The easiest approach is setting a 100% value and also column widths, for example, the following code generates a table from left margin to right margin using the default page size:

$docx = new CreateDocx();

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

);

$options = array(
    'columnWidths' => array(2100,2100,2100,2100),
    'tableWidth' => array('type' => 'pct', 'value' => 100),
);

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

$docx->createDocx('output');

Regards.