Forum


Replies: 2   Views: 233
Customizewordcontent not allowing change

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.