Forum


Replies: 1   Views: 502
Assign word headings using html contents
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 netengine_at  · 24-05-2023 - 07:53

Hi,

I have the Premium v.14 of phpdocx.

I've tried to get HTML headline (<h1>, <h2>, ..) to be used as Word headline, but I just can't get it to work.
When I click on the headlines in Word, they are marked as "Standard", not as a HL.

// in the word template I have the three headlines (Heading1PHPDOCX, Heading2PHPDOCX, ...)
$docx = new \Phpdocx\Create\CreateDocxFromTemplate($word_file);
....

// embed options
$embedHTMLoptions = [
  'disableWrapValue' => true,
  'downloadImages' => true,
  'removeLineBreaks' => true,
  'useHTMLExtended' => true,
  'wordStyles' => [
   '<h1>' => 'Heading1PHPDOCX',
   '<h2>' => 'Heading2PHPDOCX',
   '<h3>' => 'Heading3PHPDOCX',
  ],
  'strictWordStyles' => true //with and without this option
];

// tried this
$docx->embedHTML($head_html . '<p class="h1">'.$table_of_contents.'</p>', $embedHTMLoptions);

// also tried this
$docx->embedHTML($head_html . '<p class="h1" data-style="Heading1PHPDOCX">'.$table_of_contents.'</p>', $embedHTMLoptions);