Forum


Replies: 1   Views: 759
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 dan_brokerbusiness  · 24-09-2022 - 02:40

Hi

We import various heading styles from various ms word docx into a phpdocx document, apply them throughout a generated document and generate a table of contents from those headings. Everything works as expected.

Now we have a specific title that needs to look like one of the headings but should not be included in the ToC. As the style definitions come from various documents we can not simply hard code how it should look, we really need "Heading 1 Style minus the headingLevel". 

Ideally we could simply override the headingLevel property on this specific text in the paragraphParams to unset the headingLevel or set it to a higher value which could be excluded in the ToC.

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

Sadly this does not seem to work, the headingLevel of the pStyle takes precedence and can not be overwritten.

We are aware that we can create our own style using createParagraphStyle but there does not seem to be a way to read the current definition of an imported style in a format that can easily be modified and passed to createParagraphStyle.
We can see a way using the Indexer and creating the definitions from scratch, but because the original styles are out of our control and can basically contain any possible formattings this seems to be a big task for something seemingly simple.

Is there any alternative/better way?

Thanks!