Forum


Replies: 1   Views: 1261
How to make the set indent of bulleted list in table cell to 0
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 rwp40  · 07-05-2021 - 21:04

Used addList(), but there is always an indent in the cell, which I do not want.

 

Posted by admin  · 08-05-2021 - 08:35

Hello,

When a content is added to a cell two indentations/margins are applied:

  • Cell margin
  • Content indentation/margin

To remove the cell margins when using addTable you need to use the cellMargin option (or apply a custom table style to set margin values):

$valuesTable = array(
    array(
        array(
            'cellMargin' => 0,
            'value' => 'Content',
        ),
        array(
            'cellMargin' => 0,
            'value' => 'Content',
        ),
    ),
    array(
        array(
            'cellMargin' => 0,
            'value' => 'Content',
        ),
        array(
            'cellMargin' => 0,
            'value' => 'Content',
        ),
    )
);

$docx->addTable($valuesTable);

If you also want to remove the indentations/margins from the content you are adding, then you need to set custom indentations to overwrite the default ones, for example when adding a list as a WordFragment you can use a custom list style (created dynamically or imported):

$listStyleOptions = array();
$listStyleOptions[0]['type'] = 'bullet';
$listStyleOptions[0]['left'] = '1';
$listStyleOptions[0]['hanging'] = '1';
$docx->createListStyle('my_custom_list_style', $listStyleOptions);

$list = new WordFragment($docx);
$itemList = array(
    'Line 1',
    'Line 2',
    'Line 3',
);
$list->addList($itemList, 'my_custom_list_style');

$valuesTable = array(
    array(
        array(
            'cellMargin' => 0,
            'value' => 'Content',
        ),
        array(
            'cellMargin' => 0,
            'value' => 'Content',
        ),
    ),
    array(
        array(
            'cellMargin' => 0,
            'value' => 'Content',
        ),
        array(
            'cellMargin' => 0,
            'value' => $list,
        ),
    )
);

$docx->addTable($valuesTable);

Regards.