Forum


Replies: 2   Views: 1581
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 meyerandassoc  · 08-02-2017 - 20:22

I'm trying to create a table but no matter that I set the column witdths to the table is the full width of the page. 

Here are the table properties I'm using:

$tableProperties = array(
    'border'=>'single',
    'borderColor'=>'#000000',
    'borderWidth'=>10,
    'tableAlign'=>'center',
    'tableLayout'=>'fixed',
    'textProperties'=>array('fontSize'=>11,'textAlign'=>'center'),
    'columnWidths'=>array(100,100)
);

I've also tried it without the 'tableLayout' property as well as varying values for 'ColumnWidths'. 

I need both columns to be equal widths, and the table to be approximately 2.5 inches wide. I'd settle for using the 'width' property of tableData but I can't find any code examples.

 

Thanks

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.

Posted by meyerandassoc  · 09-02-2017 - 08:16

Thank you very much. The 'tableWidth' property solved my problem.