Forum


Replies: 2   Views: 513
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 s.montanarella  · 22-06-2021 - 15:08

Hi',

I'm trying to insert a word character inline style:
 

...
<td>
-
</td>
<td>
<p class="Etichettamenu">msg 2</p> <span>Text</span>
</td>
...
      "wordStyles": {
        ".h1": "Titolo1",
        ".h2": "Titolo2",
        ".h3": "Titolo3",
        ".h4": "Titolo4",
...
        ".Etichettamenu": "Etichettamenu",
      },

The template has defined the style "Etichetta menu" as a simple bold inline style.

When I open the docx the "Etichettamenu" style is not present, instead "Normal" is set.

I also try another version:

<b class="Etichettamenu">msg 2</b> <span>Testo non in grassetto</span>

Same results but obviously in bold and inline; better but it's not the expected results.

Thanks!
Federico


 

Posted by admin  · 22-06-2021 - 16:54

Hello,

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')));

Regards.

Posted by s.montanarella  · 24-06-2021 - 07:46

Thank you,

we have some issues upgrading from an older version; we found a solution from your suggestion!

Ciao, Federico