Forum


Replies: 1   Views: 2421
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 meverett  · 31-08-2021 - 13:51

I copied and pasted the code example here: https://www.phpdocx.com/api-documentation/word-content/add-table-Word-document-with-PHP and the table generated had a column width of .0001 inches in Google Docs and Microsoft Word by default. I am using the trial version. Is there something I need to do to make tables span the full width of the page? I believe that is the intended behavior for tables but it is not happening for me 

Edit: I removed the columnWidths option so that is not what was stopping it from going full width

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.