Forum


Replies: 4   Views: 305
Tabs in list
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 IHD  · 10-12-2018 - 14:35

Hi, 

Is it not possible to set tabPositions when using addText method on a wordFragment which is then included as a list item? 

The following code should do it: 

$docx = new CreateDocx();


$textData = new WordFragment($docx);
$tabs = array();
$tabs[] = array('position' => 4000, 'leader' => 'dot');
$tabs[] = array('position' => 6000, 'leader' => 'dot');
$tabs[] = array('position' => 8000, 'leader' => 'dot');
$options = array('tabPositions' => $tabs);

$text = array();
$text[] = array('text' => 'one');
$text[] = array('text' => 'two', 'tab' => true);
$text[] = array('text' => 'three', 'tab' => true);

$textData->addText($text, $options);

$itemList= array(
    'In this example we use a custom list (val = 5) that comes bundled with the default PHPdocX template.',
    array(
        $textData,
        'Line B',
        'Line C'
    ),
    'Line 3',
);

// set the style type to 5: other predefined Word list style
$docx->addList($itemList, 5);

$docx->createDocx('example_addList_3');

The tabs work fine if i run $docx->addText($text, $options);  and then just create the document, but it does not work as expected when running $textData->addText($text, $options); and then including $textData as a list item. 

Any idea/workaround? 

Thanks.

 

Posted by admin  · 10-12-2018 - 14:48

Hello,

What version and license of phpdocx are you using?

Regards.

Posted by IHD  · 10-12-2018 - 15:00

Hi, 

Using version 8.0 with an advanced license. 

Posted by admin  · 10-12-2018 - 15:22

Hello,

Thanks for posting the license you are using.

Tabs are paragraph styles, and you can't mix text paragraph styles to list item styles, only run-of-text styles can be applied. The best solution is using a custom paragraph style with the tabs styles set, imported from an existing DOCX or created from scratch, and set it to the list using the pStyle option (https://www.phpdocx.com/api-documentation/word-content/insert-list-nested-Word-document-with-PHP); or using the useWordFragmentStyles option with custom paragraphs styles available in the addList method too.

The addList/sample_5.php sample included in all packages illustrates how to apply the useWordFragmentStyles option.

Regards.

Posted by IHD  · 10-12-2018 - 16:11

Thanks, works like a charm!