Replies: 12   Views: 3692
Custom list style issues
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 tutotours  · 11-09-2017 - 21:29

Hello !

I have some problems with custom list styles.


First, this code doesn't seem to work to make list left indent to 0 :

$itemsOptions[0]['type'] = 'upperLetter';
$itemOptions[0]['left']= 0;

// create the list style with name: latin
$docx->createListStyle('items', $itemsOptions);
$docx->replaceVariableByHTML('BODYCOLLE', 'block', $html, array(
            'downloadImages' => true,
            'parseDivsAsPs' => true,
            'customListStyles' => true

UpperLetter option is working fine but left option doesn't.


I also have some list items which have line breaks before them with no reason. I checked HTML and the line break is not there in it but appears in the Docx.

Ex : 

Should be : 

A. Item 1

Appears as :


Item 1


I saw that it's happening when I have images or a line with bold writing on the line before.

I can send you an example if you don't know what I mean.

Posted by admin  · 12-09-2017 - 07:04


The minimum value allowed by the left property is 1. It you set 0, phpdocx sets the default value.

About line breaks, they are only added when the content is a block type or there's some line break. We recommend you to check the HTML you are adding, and use display inline or float left properties if needed. The replaceVariableByHTML method also includes the type option that allows to do block or inline replacements, that can be useful for some placeholders.


Posted by tutotours  · 12-09-2017 - 14:27

Hello ! 

I tried setting left to 1 like this :

$itemsOptions[0]['type'] = 'upperLetter';
$itemOptions[0]['left']= 1;
$docx->createListStyle('items', $itemsOptions);
$docx->replaceVariableByHTML('BODYCOLLE', 'block', $html, array(
            'downloadImages' => true,
            'parseDivsAsPs' => true,
            'customListStyles' => true

And it didn't change anything.


Using inline instead of block in replaceVariableByHTML removes all paragraphs and lists elements.

Here's an example of HTML I'm using : 

La liaison σ est plus stable que la liaison π


Posted by admin  · 12-09-2017 - 15:50


The left option is working fine, you can test it running this simple sample:


require_once 'classes/';

$docx = new CreateDocx();
// custom options
$latinListOptions = array();
$latinListOptions[0]['type'] = 'lowerLetter';
$latinListOptions[0]['format'] = '%1.';
$latinListOptions[0]['left'] = 1;
$latinListOptions[1]['type'] = 'lowerRoman';
$latinListOptions[1]['format'] = '%1.%2.';

// create the list style with name: latin
$docx->createListStyle('latin', $latinListOptions);

// list items
$myList = array('item 1', array('subitem 1.1', 'subitem 1.2'), 'item 2');

// insert custom list into the Word document
$docx->addList($myList, 'latin');

// save the Word document

But it seems the problem is that you are not setting the list style to the list of the HTML. The customListStyles option doesn't assign a style ID to a list, you need to use the wordStyles option. there're some samples of this property on this page:

Or you can use DOCXCustomizer to change the style ID of a list:

Or use the addList method instead of HTML if you want to have more control:

About inline and block types we just explaining that could be useful for some replacements, not your exact case.


Posted by tutotours  · 15-09-2017 - 11:06

Hello !

Would it be possible to import a list style from the template I use ? I looked at the documentation but I don't understand what the id parameter is in importListStyle method. 


My list style in the Word Template is named Items.

Posted by admin  · 15-09-2017 - 13:21


You can use a list style created with createListStyle, existing in a DOCX template or imported from an external DOCX using importListStyle. Any of these list syles can be used when you create lists to set their styles.

The id option available in the importListStyle method is the list style id to be imported. If you don't the exact id, you can use the parseStyles method to get it.


Posted by tutotours  · 15-09-2017 - 13:51

And how do I use a list style contained in a template ? 


With ParseStyle method, how can I style a list with a specific class with a list style created in a template DOCX ?

Posted by tutotours  · 15-09-2017 - 14:06

Deleted by tutotours · 15-09-2017 - 14:12

Posted by admin  · 15-09-2017 - 14:06


You just need to set the list style to the list you want to add (using embedHTML or addList methods).  The parseStyle method generates a DOCX to open it with MS Word or LibreOffice and find out the ID of each style from a DOCX (you can consider this method as a help to read with a program the existing IDs).

We recommend you to run the included sample of the parseStyle method to understand the information it returns and the sample available for the importListStyle method:


Posted by tutotours  · 15-09-2017 - 14:13

Found it. Thank you for your help.


I have a last question about lists. I have multiples lists styled with importListStyle. But instead of starting back to 1 for each list, the numbering continue from the first to the last list. Why is that ?

Posted by admin  · 15-09-2017 - 14:41


That's how MS Word works. If you use the same style ID, MS Word show it as 'Continue numbering'. The only solution to this issue is using other style (generated with MS Word in the base template or imported using other name with the importListStyle method).


Posted by tutotours  · 15-09-2017 - 14:53

It doesn't do that when I use createCustomStyle, even if I apply the same style to all my lists. Do you know why ?

Posted by admin  · 15-09-2017 - 15:02


Because the library can generate a new numbering ID using the same style or even the same name as some methods of phpdocx do.