Forum


Replies: 2   Views: 4262
Trouble setting a table's column widths
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  · 09-02-2017 - 08:06

Hello,

By default all tables extend to fit the full width of the page.

You can overwrite this behaviour using a table style or the tableWidth option:

<?php

require_once 'classes/CreateDocx.inc';

$docx = new CreateDocx();

$valuesTable = array(
    array(
        11,
        12,
    ),
    array(
        21,
        22,
    ),
    array(
        31,
        32,
    ),
);

$tableProperties = array(
    'border' => 'single',
    'borderColor' => '#000000',
    'borderWidth' => 10,
    'tableAlign' => 'center',
    'tableLayout'=>'fixed',
    'textProperties' => array('fontSize' => 11, 'textAlign' => 'center'),
    'columnWidths' => array(2000, 2000),
    'tableWidth' => array('type' => 'dxa', 'value' => 4000),
);

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

$docx->createDocx('output');

For further information about the tableWidth option please check this API doc:

http://www.phpdocx.com/api-documentation/word-content/add-table-Word-document-with-PHP

Regards.