Hello,
If you are using the conversion plugin based on libreoffice, did you install and enable the macro as the documentation in the docs folder details? Please follow the steps explained on https://www.phpdocx.com/documentation/conversion-plugin/debugging-libreoffice to debug the conversion plugin based on LibreOffice.
About the other question, TOC can be added as WordFragment to documents created from scratch or to templates. Please check the included sample examples/Core/addTableContents/sample_2.php that details adding a TOC as WordFragment to a DOCX.
Regards.