Replies: 2   Views: 1043
Word character style with embedhtml
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  · 22-06-2021 - 16:54


A custom character style can't be applied to a paragraph tag. Paragraph contents allow applying custom paragraph styles.

You can apply a custom character style to a and span tags. We recommend you to check the following included sample: Core/embedHTML/sample_4.php, that illustrates how to apply custom paragraph, character and table styles when transforming HTML to DOCX (the sample uses new custom styles but you can also apply existing and imported styles). From the previous sample:

$style = array(
    'color' => '999999',
    'border' => 'single',
    'borderWidth' => 12,
    'indentLeft' => 920,
$docx->createParagraphStyle('myParagraphStyle', $style);

$style = array(
    'bold' => true,
    'color' => 'ff0000',
    'font' => 'Arial',
    'fontSize' => 18,
    'italic' => true,
    'underline' => 'single',
$docx->createCharacterStyle('myCharacterStyle1', $style);

$style = array(
    'color' => '0000ff',
    'fontSize' => 21,
    'underline' => 'double',
$docx->createCharacterStyle('myCharacterStyle2', $style);

$docx->embedHTML('<p class="myParagraphStyle">This <span class="myCharacterStyle1">paragraph</span> uses <span class="myCharacterStyle2">custom </span> styles.</p>', array('wordStyles' => array('.myParagraphStyle' => 'myParagraphStyle', '.myCharacterStyle1' => 'myCharacterStyle1', '.myCharacterStyle2' => 'myCharacterStyle2')));