Forum


Replies: 3   Views: 324
Template with fixed height table rows
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 appstation  · 30-06-2023 - 14:06

Hi,

I'm working with a test document template that has a table with 3 columns and 4 rows in. The 2nd row has a row height specified to be "Exactly" 1cm. In word this works properly where any extra text that does not fit in the cell is hidden.

 

When doing the same with phpdocx though, the row height keeps growing to fit all content ignoring the "exact" height that was set on that row. Is there a way to actually fix the height of rows in phpdocx so I can match the behaviour to word?

 

I'm using v14 premium if this helps. Thanks

Posted by admin  · 30-06-2023 - 15:07

Hello,

Yes, you can use the height option applied to specific rows.

The following sample set a height of 1cm for the second row:

$trProperties = array();
// the second position of the array is the second row
$trProperties[1] = array(
    'height' => 567,
);

$values = array(
    array(
        11,
        12,
        13,
        14
    ),
    array(
        21,
        22,
        23,
        24
    ),
    array(
        31,
        32,
        33,
        34
    ),

);

$docx->addTable($values, array(), $trProperties);

As a fixed height (Exactly value) is applied to the row, if you add extra content into the cell higher than the row height it won't appear.

If needed you can also set fixed width sizes for the table and columns.

Regards.

Posted by appstation  · 30-06-2023 - 15:25

Is it possible to do this on a table that already exists in the template?

My problem is I won't be using a fixed template. So I need to be able to force this fixed height (if enabled on a row in word) 

My aim is just to populate the document with modifyInputFields or replaceVariableByText and if it's a fixed height row don't change size at all.

Posted by admin  · 30-06-2023 - 16:41

Hello,

You can use DOCXCustomizer to change styles on-the-fly.

For example:

$docx = new CreateDocx();

$trProperties = array();
$trProperties[1] = array(
    'height' => 567,
);

$values = array(
    array(
        11,
        12,
        13,
        14
    ),
    array(
        21,
        22,
        23,
        24
    ),
    array(
        31,
        32,
        33,
        34
    ),

);

$docx->addTable($values, array(), $trProperties);

$docx->createDocx('output_1');

$docx = new CreateDocxFromTemplate('output_1.docx');

// get the content to be changed
$referenceNode = array(
    'type' => 'table-row',
    'occurrence' => 2,
    'parent' => 'w:tbl[1]/',
);

$docx->customizeWordContent($referenceNode,
    array(
        'height' => 1067,
    )
);

$docx->createDocx('output_2');

Please note that in this case at least one row style must exist to handle it.

In the examples/DocxCustomizer folder of the Premium package you can find many samples using this method. For example, sample_10.php creates and updates a table using addTable and DOCXCustomizer.

DOCXPath methods allows to query contents to get information and do other tasks: https://www.phpdocx.com/documentation/introduction/docxpath

Please note that in these cases, with a very specific task to be done, we recommend opening a support ticket (https://www.phpdocx.com/support) with a sample DOCX and the output you want to get, so the dev team can generate a custom script using it or even adding a minor new feature or new method if the task require it.

Regards.