Forum


Replies: 2   Views: 1158
Embedhtml ul class and word style
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  · 03-09-2021 - 11:50

Hello,

A custom paragraph style can't be applied to ul tags. UL tags allow applying a custom list style; example Core/embedHTML/sample_2.php:

$latinListOptions = array();
$latinListOptions[0]['type'] = 'lowerLetter';
$latinListOptions[0]['format'] = '%1.';
$latinListOptions[1]['type'] = 'lowerRoman';
$latinListOptions[1]['format'] = '%1.%2.';
$docx->createListStyle('latin', $latinListOptions);

$html = '
<ul class="latin">
    <li>First item.</li>
    <li>Second item with subitems:
        <ul>
            <li>First subitem.</li>
            <li>Second subitem.</li>
        </ul>
    </li>
    <li>Third item.</li>
</ul>';
$docx->embedHTML($html, array('customListStyles' => true));

A custom paragraph style can be applied to block elements such as p and li tags, for example:

$latinListOptions = array();
$latinListOptions[0]['type'] = 'lowerLetter';
$latinListOptions[0]['format'] = '%1.';
$latinListOptions[1]['type'] = 'lowerRoman';
$latinListOptions[1]['format'] = '%1.%2.';
$docx->createListStyle('latin', $latinListOptions);

$style = array(
    'italic' => true,
    'underline' => 'dash',
);
$docx->createParagraphStyle('myParagraphStyle', $style);

$html = '
<ul class="latin">
    <li class="myParagraphStyle">First item.</li>
    <li class="myParagraphStyle">Second item with subitems:
        <ul>
            <li>First subitem.</li>
            <li>Second subitem.</li>
        </ul>
    </li>
    <li class="myParagraphStyle">Third item.</li>
</ul>
';
$docx->embedHTML($html, array('customListStyles' => true, 'wordStyles' => array('.myParagraphStyle' => 'myParagraphStyle')));

If you want to avoid adding some default styles (such as the base color) you need to use strictWordStyles or addDefaultStyles options. Otherwise these default styles will have more priority than the ones applied to the custom style.

You can also add a custom numbering style to a custom paragraph style: examples/LayoutAndGeneral/createParagraphStyle/sample_3.php

Regards.