Forum


Replies: 4   Views: 1577
Nested list styles
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 admin  · 21-01-2021 - 16:06

Hello,

MS Word doesn't allow setting some styles to inline elements, for example you can't set a margin to a run-of-text content (such as a strong tag when importing HTML). You need to use block tags, for example:

$html = '
<ol class="customStyle">
  <li>
    <strong>this text aligns correctly together with list</strong>
    <ol>
      <li>Lorem ipsum dolor sit amet, consectetur adipiscing elit.</li>
      <li>Lorem ipsum dolor sit amet, consectetur adipiscing elit.</li>
    </ol>
    <p style="margin-left: 50px;">
        <strong>this text doesnt align correctly</strong>
    </p>
    <ol>
      <li>Lorem ipsum dolor sit amet, consectetur adipiscing elit.</li>
      <li>Lorem ipsum dolor sit amet, consectetur adipiscing elit.</li>
    </ol>
  </li>
</ol>
';
$docx->embedHTML($html);

On the HTML API documentation you can find a detailed list of the tags and the supported styles when transforming HTML.

For the second approach (multiple list styles in the same list), you'd need to use override list styles. In the included sample LayoutAndGeneral/createListStyle/sample_4.php you can find a sample that illustrates how to create override list styles, that can be applied to lists created with addList and HTML contents.

Regards.