Forum


Replies: 2   Views: 1637
Customizewordcontent not allowing change
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 dannyguest  · 18-05-2020 - 09:16

Morning, 

I am attempting to use customizeWordContent to change the font colour of the "Heading 1" style of predefined headers within a template. 

Here is my code:

$referenceNode = array(
                'type' => 'Heading 1'
            );

            $phpdocx->customizeWordContent($referenceNode, 
                array(
                    'color' => '#000000'
                )
            );

What am I doing wrong? All I want to do is in some situations change the colour. 

Posted by admin  · 18-05-2020 - 10:51

Hello,

'Heading 1' is not an allowed type (https://www.phpdocx.com/api-documentation/docxcustomizer/customize-docx-Word-documents-PHP):

type  string  * (all), break, image, list, paragraph, run, section, style, table, table-row, table-cell.

Please check the included sample examples/DocxCustomizer/sample_9.php that changes styles from the style target. For example:

$referenceNode = array(
    'target' => 'style',
    'type' => 'style',
    'attributes' => array('w:styleId' => 'myStyle'),
);

$docx->customizeWordContent($referenceNode, 
    array(
        'bold' => false,
        'italic' => false,
        'backgroundColor' => 'FF0000',
        'caps' => false,
        'lineSpacing' => 240,
    )
);

Please note the previous sample uses the attribute w:styleId that may not be the same that the style name. Heading1 should be the styleId for Heading 1 . Using parseStyles you can get the styles from an existing DOCX.

Regards.

Posted by dannyguest  · 19-05-2020 - 07:56

That worked for me thank you for the help as always.