Forum


Replies: 2   Views: 3013
List with different textalign of items
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 LawCarta  · 25-01-2017 - 07:02

Hello Everyone

Please help me to solve my problem. I want to add list with 5 items, and I want to align 1st one by right side, so my code:

$textFragment->addText('someText', ['textAlign' => 'right']);
$itemList = array(
    $textFragment,
    'Line 2',
    'Line 3',
    'Line 4',
    'Line 5'
);
$docx->addList($itemList, 1);


But "textAlign" option is ignored in this case. Also I check inlineWordML() method and I found that Word XML with alignment is cut here. If I add "bold" option - I can see it in rawML, but alignment is ignored. So, maybe I'm wrong with it, please help me to find a solution.

Posted by admin  · 25-01-2017 - 07:50

Hello,

When you create a list, all paragraphs share the same styles (in Word lists are paragraphs with a style and a level). You have four ways to accomplish what you need:

  • Add two lists with distinct aligns
  • Use a custom list style and the importListStyle method
  • Use a template
  • Use the useWordFragmentStyles option. This option allows to overwrite the default styles using a paragraph style. This example is included in the package (addList folder):
<?php

require_once 'classes/CreateDocx.inc';

$docx = new CreateDocx();

$item1 = new WordFragment($docx);
$item1->addText('Line 1', array('pStyle' => 'Heading1PHPDOCX'));
$item2 = new WordFragment($docx);
$item2->addText('Line 2', array('pStyle' => 'Heading2PHPDOCX'));
$item3 = new WordFragment($docx);
$item3->addText('Line 3', array('pStyle' => 'Heading3PHPDOCX'));

$itemList = array(
    $item1,
    $item2,
    $item3,
);

$docx->addList($itemList, 1, array('useWordFragmentStyles' => true));

$docx->createDocx('example_addList_5');

Regards.

Posted by LawCarta  · 25-01-2017 - 08:20

Thanks, I updated library to version 6.5 and I really found this example (in 6.0 there were only 4 examples for lists). 

I think it solves my problem. Thank you!