Mark Morris
Mark Morris

Reputation: 41

How to use multiple styles for the same depth heading?

I'm having a bit of trouble with PHPWord. Trying to use addTitle with the same depth but with a different styles. Im current defining my styles at the top of the page, i tried to overwrite them on the fly but unfortunately it doesnt work.

I can see this is already an issue on github. https://github.com/PHPOffice/PHPWord/issues/1397

Link to documentation https://phpword.readthedocs.io/en/latest/

$phpWord->addTitleStyle(1, $fontStyles["HEADING_ONE_SPLIT"], $paragraphStyles["HEADING_ONE_DEFAULT"]);

$sceneSection->addTitle('MY TITLE', 1);

$phpWord->addTitleStyle(1, $fontStyles["HEADING_ONE_SPLIT"], $paragraphStyles["HEADING_ONE_SPLIT"]);

$sceneSection->addTitle('MY TITLE WITH DIFFERENT STYLE', 1);

Basically the style does not change at all. Im adding a tab and aligning to left with the 2nd Title Paragraph Style, but it doesnt get applied.

Just a note my Font Styles & Paragraph Styles work perfect on different depths. The problem is i create a TOC based on them depth but some titles need different styles per depth.

Upvotes: 1

Views: 635

Answers (1)

ejuhjav
ejuhjav

Reputation: 2710

PHPword (0.16.0) doesn't seem to support redefining already existing title styles (or any named style for that matter) - if a title style for certain depth is already defined, the second addTitleStyle call is just ignored. You can check setStyleValues function in Style.php in the source for more the details.

Upvotes: 1

Related Questions