Forum


Replies: 1   Views: 785
Modify imported style on the fly
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  · 24-09-2022 - 08:42

Hello,

Your explanation is correct. An outline level set in a style can't be overridden in the paragraph styles. For this reason, this won't work:

$docx->addText('Test Heading', [
   'pStyle'       => 'Heading1',
   'headingLevel' => 9
]);

You can see this same behaviour in MS Word. If you apply a Heading style to a paragraph, then you can't set a custom Outline level for this paragraph (right click => Outline level option appears disabled). There's no specific tag to exclude a content from TOCs but using another style or do not apply a custom style.

DOCXCustomizer allows customize styles on-the-fly but to accomplish your task you need:

  • Clone an existing MS Word style and create a new style with the same styles but with a new name and a new styleId.
  • Handle external dependencies from the cloned style (basedOn tag).
  • Remove the outline level from the new style.

There's no method in the current version of phpdocx to accomplish this task. DOCXPath allows doing these workflows but only with contents, not styles. A DOCXPathStyles feature would be required, but this feature is in the roadmap to be included in a future release of phpdocx.

Please send an email to contact[at]phpdocx.com, so we can send you a proposal.

Regards.