Hello,
UPDATE: https://www.phpdocx.com/documentation/cookbook/working-with-headings
If you run
$docx->addText('Contents',array('pStyle' => 'Heading1'));
and you don't get a custom paragraph style applied to that content is because your DOCX doesn't include that style name (Heading1). Please test and run the included sample Core/addTableContents/sample_2.php that applies custom paragraph styles included in the default template of phpdocx, for example:
$docx->addText('Chapter 1', array('pStyle' => 'Heading1PHPDOCX'));
If you don't know the name of the style/s you want to apply, you can get them using importStyles (https://www.phpdocx.com/api-documentation/layout-and-general/import-styles-from-a-Word-document-with-PHP). On https://www.phpdocx.com/documentation/practical/styles you can read the practical guide about using styles with phpdocx.
Regards.