Forum


Replies: 1   Views: 498
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);

Posted by admin  · 24-05-2023 - 08:45

Hello,

Please check the information available on Working with headings using PHP methods and HTML contents that details how to accomplish this task.

Please note that if you are using a custom template, then your heading style names may not be the same. As explained on the previous page:

The base phpdocx template doesn't include the Heading 1 or Heading 2 styles but some other ones called Heading1PHPDOCX, Heading2PHPDOCX...

Using a custom DOCX template, you can get the available style names using Indexer, getWordStyles or parseStyles.

Please also note, that as your license includes LUS, if you send to contact[at]phpdocx.com the DOCX template you are using we'll check it and generate a custom sample script.

Regards.